i want to make a dynamic listview with numberd items.Here i have retrieved values from sqlite database into listview,and actually it is numberd according to their id's which stored in database.But iam using a dynamic list view,so i want to show numberd items starting from 1 in each time i load the listview.For example people booking flight tickets for diffrent dates and flight authorities will display a final listview for the current date including the persons who booked for that date.
consider today is 10-12-2014
person A booked ticket for the date 12-12-2014, so his "id" might be "1" in database.
person B booked ticket for the date 13-12-2014,so his "id" might be "2" in database.
person c booked ticket for the date 13-12-2014,so his "id" might be "3" in database.
but when the day "13-12-2014" comes person B's id should be "1"(no need to have any connection with database, just enough a numberd representation to show today's list is this.
like
1.person B
2.person C
thats all.
this is my displayadapter class
public class DisplayAdapter extends BaseAdapter {
private Context mContext;
private ArrayList<String> id;
private ArrayList<String>name;
private ArrayList<String>phone;
public DisplayAdapter(Context c, ArrayList<String> id,ArrayList<String> name, ArrayList<String> phone) {
this.mContext = c;
this.id = id;
this.name = name;
this.phone = phone;
}
public int getCount() {
// TODO Auto-generated method stub
return id.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView(int pos, View child, ViewGroup parent) {
Holder mHolder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.viewthem, null);
mHolder = new Holder();
mHolder.txt_id = (TextView) child.findViewById(R.id.d);
mHolder.txt_name = (TextView) child.findViewById(R.id.nm);
mHolder.txt_phone = (TextView) child.findViewById(R.id.ph);
child.setTag(mHolder);
} else {
mHolder = (Holder) child.getTag();
}
mHolder.txt_id.setText(id.get(pos));
mHolder.txt_name.setText(name.get(pos));
mHolder.txt_phone.setText(phone.get(pos));
return child;
}
public class Holder {
TextView txt_id;
TextView txt_name;
TextView txt_phone;
}
}
this is my dbhelper class
mydb = new DBhelper(this);
SQLiteDatabase database = mydb.getWritableDatabase();
Cursor mCursor=database.rawQuery("SELECT * FROM contacts WHERE dt='"+d+"'", null);
userId.clear();
user_name.clear();
user_phone.clear();
if (mCursor.moveToFirst()) {
do {
userId.add(mCursor.getString(mCursor.getColumnIndex(DBhelper.CONTACTS_COLUMN_ID)));
user_name.add(mCursor.getString(mCursor.getColumnIndex(DBhelper.CONTACTS_COLUMN_NAME)));
user_phone.add(mCursor.getString(mCursor.getColumnIndex(DBhelper.CONTACTS_COLUMN_PHONE)));
} while (mCursor.moveToNext());
}
DisplayAdapter disadpt = new DisplayAdapter(token.this,userId, user_name, user_phone);
obj.setAdapter(disadpt);
disadpt.notifyDataSetChanged();
mCursor.close();
Aucun commentaire:
Enregistrer un commentaire