问题
Is it possible to Get the GridLayout items from the Adapter in Android.
Like, The items in the GridView come from the ListAdapter associated with this view.
Please clarify my doubt.. Thanks
回答1:
Gridlayout doesn't have any Adapters as its not derived from AbsListView . Only GridView comes with Adapters.
回答2:
Yes, it is possible. You don;t say what you are using to create the GridView. Following is an example of getting the data from a cursor when you click on a cell of the grid (and putting it into an intent to call another activity):
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id) {
Cursor c = (Cursor) (parent.getAdapter().getItem(position));
Intent i = new Intent(mCtx, ScheduleEdit.class);
i.putExtra("RowId", position);
i.putExtra("Machine", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_MACHINE)));
i.putExtra("Priority", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_PRIORITY)));
i.putExtra("RunJob", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_RUNJOB)));
i.putExtra("Operator", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_OPERATOR)));
i.putExtra("NxtJob1", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_NXTJOB1)));
i.putExtra("NxtJob2", c.getString(c
.getColumnIndex(ScheduleDBAdapter.SCHEDULE_NXTJOB2)));
startActivityForResult(i, ACTIVITY_EDIT);
}
});
来源:https://stackoverflow.com/questions/11309597/how-gridlayout-items-come-from-the-adapterlist-image-in-android-app