I want to populate list view from arraylist returned from ormlite
here is code where I retrieve data from ormlite
how can i populate listview with all colymns of my table
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));
and my adapter class is below
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 in advance
you have to get those values form the list like this in adapter getView() method
look at this tutorial Custom adapter for listview it will solve your problem..