开发者

ClassCastException android.view.viewgroup.$layoutParam

开发者 https://www.devze.com 2023-04-07 03:45 出处:网络
TextView txt=new TextView(productlist.this); txt.setText(author.get(groupPosition)); TextView txt1=new TextView(productlist.this);
 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


Make sure you import the correct LayoutParams.

  • android.widget.LinearLayout.LayoutParams for LinearLayout
  • android.view.ViewGroup.LayoutParams for TextView
0

精彩评论

暂无评论...
验证码 换一张
取 消