How GridLayout items come from the Adapter(List/Image) in Android App

情到浓时终转凉″ 提交于 2019-12-18 04:21:57

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!