程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> listview-自定義的lisView沒有正確顯示

listview-自定義的lisView沒有正確顯示

編輯:編程綜合問答
自定義的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;

}
}

最佳回答:


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

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved