im working on a listview that can have different types of layouts. I have a viewholder with all the views from all the different layouts possible. I use a switch statement depending on the type to choose which layout needs to be inflated. The problem i'm having is with textViews. I am unable to set the text on the textview holder1.textview. the error i get is "Attempt to invoke virtual method 'void android.widget.textview.settext(java.lang.charsequence)' on a null object reference. I am able to set imageviews

if(convertView==null)
{
    holder1 = new ViewHolder();

    switch(type){

    case 0:
        convertView= LayoutInflater.from(context).inflate(
                R.layout.layout1, parent, false);

     holder1.mainpic=(ImageView)convertView.findViewById(R.id.mainimage);


         holder1.textview = null;   
        break;

    case 1:
        convertView= LayoutInflater.from(context).inflate(
                R.llayout.layout2, parent, false);

         holder1.textview =(TextView)convertView.findViewById(R.id.textview_layout2);
     break;

    case 2:
        convertView= LayoutInflater.from(context).inflate(
                R.layout.layout3,parent false);


     break;




    }





    convertView.setTag(holder1);
}
else
{
    holder1= (ViewHolder) convertView.getTag();

}



    if(type ==1)
       {
        holder1.textview.settext("hello ");
        }

Related posts

Recent Viewed