我已经在 sqlite 中实现了一个具有一个表的数据库。我已经编写了数据检索方法。但是在我检索到一列并将其存储在游标中之后,如何在列表视图或列表活动中显示该列
问问题
81 次
1 回答
1
试试这个示例代码:
获取 ArrayList 中的列数据:
ArrayList<String> data = new ArrayList<String>();
data= // get your column data here
然后设置 Array Adapter 类:
public class ListArrayAdapter extends ArrayAdapter<String> {
private Context context;
private ArrayList<String> list;
private ListView listView;
public GalleryListArrayAdapter(Context context, ArrayList<String> list, ListView listView) {
super(context, R.layout.fragment_list_item, list);
this.context = context;
this.list = list;
this.listView = listView;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int pos = position;
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.fragment_list_item, parent, false);
return rowView;
}
}
于 2013-06-17T09:33:08.707 回答