我想从ormlite返回的arraylist填充列表视图
这是我从ormlite
检索数据的代码如何使用我表格中的所有colymns填充listview
public class dinnerList extends Activity {
ArrayList<CanteenTagEntry> dinnerlist;
ListView lv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview_item_row);
Context con = getApplicationContext();
DatabaseHelper dbHelper = new DatabaseHelper(con);
ICanteenLogRepository canteenrepo = dbHelper.getCanteenLogRepository();
try {
dinnerlist = (ArrayList<CanteenTagEntry>) canteenrepo.Retrieve();
System.out.print(dinnerlist);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new CanteenAdapter(this, dinnerlist));
我的适配器类在
之下public class CanteenAdapter extends BaseAdapter {
private Context context;
private List<CanteenTagEntry> lis;
public CanteenAdapter(Context c, List<CanteenTagEntry> li) {
// TODO Auto-generated method stub
context = c;
lis = li;
}
public int getCount() {
// TODO Auto-generated method stub
return lis.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater
.inflate(R.layout.listview_item_row, null);
}
TextView textview1 = (TextView) convertView
.findViewById(R.id.Title1);
TextView textview2 = (TextView) convertView
.findViewById(R.id.Title2);
TextView textview3 = (TextView) convertView
.findViewById(R.id.Title3);
TextView textview4 = (TextView) convertView
.findViewById(R.id.Title4);
return convertView;
}
}
提前thanx
答案 0 :(得分:2)
你必须在适配器getView()方法
中从列表中获取这些值CanteenTagEntry entry = new CanteenTagEntry();
entry = lis.get(position);
查看本教程Custom adapter for listview它将解决您的问题..