嗨我的android應用程序有一個listactivity這個活動調用從另一個活動與Intent調用後,在ListActivity的onCreate方法創建一個新的AsynchTask並調用Web服務,並把所有的東西到我的ArrayList數據來自Web服務是好的,但當我嘗試實現getArrayAdapter的getView時,它會變得更加奇怪,它有時會顯示列表的內容有時候不是,有時當我滾動時。這裏是我的getView方法的自定義適配器。 (布=的TextView + ListView控件)ListView不正確顯示自定義arrayadapter?
class EntryDetailsAdapter extends ArrayAdapter<Entry>{
private ArrayList<Entry> entryDetails;
private Entry tempEntry;
public EntryDetailsAdapter(Context context, int textViewResourceId,
List<Entry> objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
entryDetails = (ArrayList<Entry>) objects;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View mView = convertView;
if(mView == null){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = inflater.inflate(R.layout.entry_rows, null);
}
tempEntry = entryDetails.get(position);
//data is fine but problem is while occur while showing data
if(tempEntry != null){
//get the textview from list row xml that i defined
TextView textView = (TextView) findViewById(R.id.entryRowTextView);
if(textView != null){
//i dont know why but this sometimes giving null so check
textView.setText(tempEntry.getEntryContent());
}
}
return mView;
}
}
[注]問題可能類似於this question但我不能找到一個解決方案
感謝您解決我的問題的答案 – 2010-12-19 08:52:30