我已经在sqlite中实现了一个有一个表的数据库。我已经编写了数据retreival方法。但是在我检索了一个列并将其存储在游标中之后,如何在列表视图或列表活动中显示该列< / p>
答案 0 :(得分: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;
}
}