4
 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

0

1 Answer 1

13

Make sure you import the correct LayoutParams.

  • android.widget.LinearLayout.LayoutParams for LinearLayout
  • android.view.ViewGroup.LayoutParams for TextView
Sign up to request clarification or add additional context in comments.

1 Comment

I had this same problem, but it only manifested itself when running on old (version 8) devices. Version 17 devices didn't complain even though I was using the 'wrong' LayoutParams. Thanks, Gallal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.