2016-09-14 10 views
0

に私は 変更ヘッダーのレイアウトプログラムでrecyclerviewadapter

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> { 
String[] titles; 
TypedArray icons; 
Context context; 
private TextView saldo; 

    RecyclerViewAdapter(String[] titles , TypedArray icons , Context context){ 

     this.titles = titles; 
     this.icons = icons; 
     this.context = context; 
} 



public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 

    TextView navTitle; 
    ImageView navIcon; 
    Context context; 

    public ViewHolder(View drawerItem , int itemType , Context context){ 

     super(drawerItem); 
     this.context = context; 
     drawerItem.setOnClickListener(this); 
     if(itemType==1){ 
      navTitle = (TextView) itemView.findViewById(R.id.tv_NavTitle); 
      navIcon = (ImageView) itemView.findViewById(R.id.iv_NavIcon); 
     } 
    } 


    @Override 
    public void onClick(View v) { 

     MainActivity mainActivity = (MainActivity)context; 
     mainActivity.drawerLayout.closeDrawers(); 
     FragmentTransaction fragmentTransaction = mainActivity.getSupportFragmentManager().beginTransaction(); 

     switch (getPosition()){ 
      case 1: 
       Fragment squadFragment = new SquadFragment(); 
       fragmentTransaction.replace(R.id.containerView,squadFragment); 
       fragmentTransaction.commit(); 
       break; 
      case 2: 
       Fragment fixtureFragment = new FixtureFragment(); 
       fragmentTransaction.replace(R.id.containerView,fixtureFragment); 
       fragmentTransaction.commit(); 
       break; 
      case 3: 
       Fragment tableFragment = new TableFragment(); 
       fragmentTransaction.replace(R.id.containerView,tableFragment); 
       fragmentTransaction.commit(); 
       break; 
      case 4: 
       Fragment bantuan = new bantuan(); 
       fragmentTransaction.replace(R.id.containerView,bantuan); 
       fragmentTransaction.commit(); 
       break; 
      case 5: 
       Fragment tentang = new tentang(); 
       fragmentTransaction.replace(R.id.containerView,tentang); 
       fragmentTransaction.commit(); 
       break; 
      case 6: 
       Fragment keluar = new keluar(); 
       fragmentTransaction.replace(R.id.containerView, keluar); 
       fragmentTransaction.commit(); 
       break; 

     } 
    } 
} 


@Override 
public RecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { 

    LayoutInflater layoutInflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     if(viewType==1){ 
      View itemLayout = layoutInflater.inflate(R.layout.drawer_item_layout,null); 



      return new ViewHolder(itemLayout,viewType,context); 
     } 
     else if (viewType==0) { 
      View itemHeader = layoutInflater.inflate(R.layout.header_layout,null); 
      saldo.findViewById(R.id.saldo); 

      saldo.setText("Android"); 
      return new ViewHolder(itemHeader,viewType,context); 
     } 






    return null; 
} 


@Override 
public void onBindViewHolder(RecyclerViewAdapter.ViewHolder holder, int position) { 

    if(position!=0){ 
     holder.navTitle.setText(titles[position - 1]); 
     holder.navIcon.setImageResource(icons.getResourceId(position-1,-1)); 
    } 

} 


@Override 
public int getItemCount() { 
    return titles.length+1; 
} 


@Override 
public int getItemViewType(int position) { 
    if(position==0)return 0; 
    else return 1; 
} 



    } 

と私のヘッダのレイアウト私のrecyclerviewadapterここ

、私はtexview内部ヘッダのレイアウトを変更したい とナビゲーション引き出しをしました

<RelativeLayout 

<TextView 
    android:layout_width="match_parent" 
    android:id="@+id/barca" 
    android:layout_height="100dp" 
    android:text=" Halo,\n\ Kios Untung Selalu" 
    android:textColor="#FFFFFF" 
    android:background="#3F51B5" 
    android:gravity="center_vertical" 
    android:textSize="20dp" 

    /> 

<TextView 
    android:layout_width="match_parent" 
    android:layout_height="110dp" 
    android:text="Sisa Saldo" 
    android:textColor="#3F51B5" 
    android:layout_below="@id/barca" 
    android:textSize="20dp" 
    android:gravity="center_vertical|center" 
    android:id="@+id/textView5" /> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="To be Updated" 
    android:id="@+id/saldo" 
    android:textSize="20dp" 
    android:layout_alignBottom="@+id/textView5" 
    android:layout_centerHorizontal="true" 
    android:layout_marginBottom="22dp" /></RelativeLayout> 

どうすればよいですか?

私はすでにRecyclerViewAdapter.ViewHolder onCreateViewHolder

それを定義しますが、GETヌルpointer.Can誰も私を助けて(OnCreate関数)mainactivityでのTextViewをdefineedしても 。あなたは

itemView.findViewById(R.id.tv_NavTitle); 

からitemViewを手に入れた私は問題だと思うthatsの事前

答えて

0

感謝。

関連する問題