我在arraylist 中有来自数据库的完整列值。但我只想在列表视图中显示消息和日期列。我的代码:
public class DisplayAllNotification extends Activity
{
ListView lv;
Context context;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.notif);
lv = (ListView) findViewById(R.id.listView1);
SqlitenotifDb db = new SqlitenotifDb(getApplicationContext(),
"notifManager", null, 1);
ArrayList<NotificationData> lstString = new ArrayList<NotificationData>();
lstString = db.getNotifications();// catch NotificationData obj
NotificationAdapter notificationAdapter = new NotificationAdapter(this,
android.R.layout.simple_list_item_1, lstString);
lv.setAdapter(notificationAdapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> a, View v, int position,
long id) {
//on click want to display 2 columns in listview
}
});
}
NotificationAdapter.java
public class NotificationAdapter extends ArrayAdapter<NotificationData>{
private Context context;
private int resource;
private ArrayList<NotificationData> objects;
public NotificationAdapter(Context context, int resource,
ArrayList<NotificationData> objects)
{
super(context, resource, objects);
// TODO Auto-generated constructor stub
this.resource = resource;
this.context = context;
this.objects = objects;
}
}