如何使用sqlite数据的setOnItemClickListener从GridView获取值

时间:2019-05-23 10:31:07

标签: java android gridview

我要Toast的所选项目的值GridView,我的值来自SQLite数据库。

public class datalist extends AppCompatActivity {

    GridView gridView;
    ArrayList<data_class> arrayList;
    data_listadapter data_listadapter= null;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_user_entry);

        gridView = (GridView) findViewById(R.id.gridview);
        arrayList = new ArrayList<>();
        data_listadapter = new data_listadapter(this,R.layout.list_item,arrayList);
        gridView.setAdapter(data_listadapter);

        final Cursor cursor = MainActivity.dbController.getdata("SELECT * FROM DATA3");
        arrayList.clear();

        while (cursor.moveToNext())
            {
                int id = cursor.getInt(0);
                String catid = cursor.getString(1);
                String catoption = cursor.getString(2);
                byte[] img = cursor.getBlob(3);
                String status = cursor.getString(4);

                arrayList.add(new data_class(id,catid,catoption,img,status));
            }

        data_listadapter.notifyDataSetChanged();

       gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
           @Override
           public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


              /////here i want Toast of catid and catoption.


           }
       });

    }
}

1 个答案:

答案 0 :(得分:1)

let fileURLs = [] _.each(pm.response.json().Drawing.File, (file) => { fileURLs.push(file.FileURL["#cdata-section"]) }); pm.environment.set("fileURLs", JSON.stringify(fileURLs)); 返回单击项的位置,并使用该位置可以获取数组列表中的项。

setOnItemClickListener