所以我有一個問題在onPostExecute方法中填充listActivity。 SingleData的結果列表是正確的...然後我使用自定義適配器綁定到android.R.id.list ...Android asynctask on listview
但它給了我錯誤...我真的不明白爲什麼... 所以這裏的適配器的代碼..:
private class RequestAdapter extends ArrayAdapter<SingleData> {
private int _resource;
private LayoutInflater _inflater;
private Context _context;
public RequestAdapter(Context context, int textViewResourceId,
List<SingleData> objects) {
super(context, textViewResourceId, objects);
_resource = textViewResourceId;
_context = context;
_inflater = LayoutInflater.from(_context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = (ListView)_inflater.inflate(_resource,null);
SingleData sdd = getItem(position);
ImageView iv = (ImageView)convertView.findViewById(R.id.imagePlaceHolder_IV);
iv.setImageBitmap(sdd.thumbIMG);
TextView tv = (TextView)convertView.findViewById(R.id.createdAt_TV);
tv.setText(sdd.timeStamp);
// TODO Auto-generated method stub
return convertView;
}
}
這裏是onPostExecute:
private class DownloadTheImages extends AsyncTask<Void, Void, List<SingleData>> {
private Context _ctx;
public DownloadTheImages(Context ctx) {
_ctx = ctx;
}
protected void onPostExecute(List<SingleData> result) {
ListView mainLV = (ListView)findViewById(android.R.id.list);
mainLV.setAdapter(new RequestAdapter(_ctx, R.layout.single_row, result));
}
protected List<SingleData> doInBackground(Void... params) {
.....
....
}
}
和logcat的:
?任何線索......感謝..
這些都是較新的錯誤:
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.makeAndAddView(ListView.java:1745)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.fillDown(ListView.java:670)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.fillFromTop(ListView.java:727)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.ListView.layoutChildren(ListView.java:1598)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.AbsListView.onLayout(AbsListView.java:1260)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.View.layout(View.java:7175)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
10-20 16:32:56.615: E/AndroidRuntime(1487): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
我會immeadetly嘗試... –
現在它給我的錯誤,在setAdapter方法的開始......我想這是在格蘭適配器的getView becaseu沒有檢查,如果obecjt賴以做getItem爲空或空...任何建議如何檢查? –
設置適配器之前,你需要初始化結果ArrayList是你在做什麼? –