通过onclick编辑Gridview数据

时间:2018-06-08 08:23:09

标签: android sqlite gridview datagridview

我想在输入错误时编辑gridview数据。 Gridview数据使用Array,Adapter,String从Sqlite填充。

当前Scrren: enter image description here

我应该可以点击每个订单项,然后根据需要修改和保存数据。

主要活动:

public void populateListView() {

  GridView gvproduct = (GridView) findViewById(R.id.gridView1);
  SQLiteDatabase db = openOrCreateDatabase("OCC", MODE_PRIVATE, null);
  List < String > li = new ArrayList < > ();
  ArrayAdapter < String > dataAdapter = new ArrayAdapter < String > (getApplicationContext(), android.R.layout.simple_spinner_item, li);
  dataAdapter.setDropDownViewResource(R.layout.activity_course_search);

  try {
    Cursor cr = db.rawQuery(" SELECT * from dataall where Scanning_Date = (select max(Scanning_Date) from dataall WHERE Scanning_Date < DATE('now'))", null);
    if (cr != null) {
      if (cr.moveToFirst()) {
        do {
          String na = cr.getString(cr.getColumnIndex("_id"));
          String no = cr.getString(cr.getColumnIndex("Material_Number"));
          String lat = cr.getString(cr.getColumnIndex("Material_Description"));
          String LONG = cr.getString(cr.getColumnIndex("Qty"));

          li.add(na);
          li.add(no);
          li.add(lat);
          li.add(LONG);

          gvproduct.setAdapter(dataAdapter);

        } while (cr.moveToNext());

      } else {
        Toast.makeText(getApplicationContext(), "No Data to show", Toast.LENGTH_LONG).show();

      }
    }

  } catch (Exception e) {
    Toast.makeText(CourseSearchActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
  }


}

0 个答案:

没有答案