alllllllll 2013-04-25 09:00 采纳率: 0%
浏览 4105
已采纳

自定义的lisView没有正确显示

异常:java.lang.UnsupportedOperationException: addView(View, LayoutParams) is not supported in AdapterView

实现代码:

protected void onCreate(Bundle paramBundle)
{
super.onCreate(paramBundle);
requestWindowFeature(1);
setContentView(R.layout.activity_main);
_listView = (ListView)findViewById(R.id.listView1);
final String[] arrayOfString = SMSHelper.getInstance(this).getSMSCategoryNames();
SMSHelper.getInstance(this).getSMSCountForCategory(arrayOfString[0]);
SMSHelper.getInstance(this).getSMSForCategory(arrayOfString[0]).get(0);
SMSHelper.getInstance(this).getSMSPreviewForCategory(arrayOfString[0], "eat");
MyCustomAdapter localMyCustomAdapter = new MyCustomAdapter(this, 0, getCategoriesData());
this.b = new Bundle();
_listView.setAdapter(localMyCustomAdapter);
_listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
  public void onItemClick(AdapterView<?> paramAnonymousAdapterView, View paramAnonymousView, int paramAnonymousInt, long paramAnonymousLong)
  {
    Intent localIntent = new Intent(MainActivity.this, SmsList.class);
    localIntent.putExtra("Category", arrayOfString[paramAnonymousInt].toString());
    MainActivity.this.startActivity(localIntent);
  }
   });
  }
   class MyCustomAdapter extends ArrayAdapter<String>
{
Context ctx;
String[] listDataForView;
int paramArrayOfString;

public MyCustomAdapter(Context paramInt, int paramArrayOfString, String[] arg4)
{
  super(paramInt, paramArrayOfString, arg4);
  this.ctx = paramInt;
  this.paramArrayOfString = paramArrayOfString;
  this.listDataForView=arg4;
}

private String getCategoriesLength(int paramInt)
{
  return SMSHelper.getInstance(this.ctx).getSMSCountForCategory(this.listDataForView[paramInt].toString());
}
public class MyCustomHolder {
    public TextView  localTextView1,localTextView2;;

}
@Override
public View getView(final int paramInt, View paramView, ViewGroup paramViewGroup)
{
     View localView=paramView;
     MyCustomHolder holder = null;


  if(localView==null){
      localView = MainActivity.this.getLayoutInflater().inflate(R.layout.listitem, paramViewGroup);
      holder = new MyCustomHolder();
      holder.localTextView1 = (TextView)localView.findViewById(R.id.textView1);
      holder.localTextView2 = (TextView)localView.findViewById(R.id.textView2);

      localView.setTag(holder);
  }
  else
  {
      holder = (MyCustomHolder)localView.getTag();
  }
  if (paramInt % 2 == 0){
      localView.setBackgroundColor(Color.parseColor("#FFDDFEFE"));
    }

  holder.localTextView1.setText(listDataForView[paramInt].toString());
  holder.localTextView2.setText(getCategoriesLength(paramInt)); 

  return localView;

}
}
  • 写回答

1条回答 默认 最新

  • jnhoodlum 2013-04-26 07:00
    关注

    应该是你的布局文件错了,看一下你的ListView是不是有子View,即
    < ListView >
    < XxxView >
    < / XxxView >
    < / ListView >
    你把< XxxView >去掉就行了

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug