Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClassCastException android.view.viewgroup.$layoutParam

 TextView txt=new TextView(productlist.this);
            txt.setText(author.get(groupPosition));
            TextView txt1=new TextView(productlist.this);
            txt1.setText(price.get(groupPosition));
            txt.setLayoutParams(new LayoutParams(70, LayoutParams.WRAP_CONTENT));  
            txt1.setLayoutParams(new LayoutParams(70,LayoutParams.WRAP_CONTENT));
            LinearLayout ll=new LinearLayout(productlist.this);
            ll.setOrientation(LinearLayout.HORIZONTAL);
            ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));  
           // ll.setGravity(Gravity.CENTER);  
            ll.addView(txt);  
            ll.addView(txt1);  

            return ll;

hi, this is the code snippet for a group view in expandable ListView which gives error:

java.lang.ClassCastException android.view.viewgroup.$layoutParam

like image 591
ritesh Mehandiratta Avatar asked Dec 13 '22 09:12

ritesh Mehandiratta


1 Answers

Make sure you import the correct LayoutParams.

  • android.widget.LinearLayout.LayoutParams for LinearLayout
  • android.view.ViewGroup.LayoutParams for TextView
like image 78
Gallal Avatar answered Jan 07 '23 22:01

Gallal