我不能做的ArrayList的ListView適配器,因爲
整個數據是從SQLite的ArrayList的<String>定義適配器
final ArrayList<String> list= helper.GetAllValues("x1", column2);
//final StableArrayAdapter adapter = new StableArrayAdapter(this, android.R.layout.simple_list_item_1, list);
final ListAdapter adapter = new ListAdapter(this, list, img);
listview.setAdapter(adapter);
ListAdapter.java
public class ListAdapter extends ArrayAdapter<String> {
private final Activity context;
private final String[] itemname;
private final Integer[] imgid;
public ListAdapter(Activity context, String[] itemname, Integer[] imgid) {
super(context, R.layout.items, itemname);
// TODO Auto-generated constructor stub
this.context=context;
this.itemname=itemname;
this.imgid=imgid;
}
public View getView(int position,View view,ViewGroup parent) {
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.items, null,true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.TitleLabel);
ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
TextView extratxt = (TextView) rowView.findViewById(R.id.SecondLabel);
txtTitle.setText(itemname[position]);
imageView.setImageResource(imgid[position]);
extratxt.setText("Description "+itemname[position]);
return rowView;
};
}
錯誤:(66 37 )錯誤:類ListAdapter中的構造函數ListAdapter不能應用於給定的類型;
需要:活動,字符串[],整數[]
發現:Listofmeals,ArrayList中,整數[]
原因:實際參數的ArrayList不能[]通過方法調用轉換被轉換成字符串
private final String[] itemname;
private final Integer[] imgid;
這是錯誤是這樣的:
txtTitle.setText(itemname[position]);
imageView.setImageResource(imgid[position]);
extratxt.setText("Description "+itemname[position]);
如何類型Arraylist我必須插入?
使用光標適配器。 – Raghunandan
到ListAdapter.java? – test
使用CursorAdapter代替ListAdapter – Raghunandan