List items not showing when reading data from SQLite db

穿精又带淫゛_ 提交于 2020-01-25 11:41:46

问题


In my android app, i m trying show a list through list adapter and the data comes from SQLite db. However the list items are not showing up , though everything is fine , i think! . This is my code for showing list

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.store_list_activity);
        float storeId = 1;
//Storedb is my data adapter class of SQLite
        StoreDb storelist = new StoreDb(this);
        storelist.open();
        ArrayList arraylist= storelist.getStoreName(storeId);
           adapter= new ArrayAdapter<String>(this, R.layout.store_list_style, arraylist);
           medicine_List= (ListView) findViewById (R.id.list);
           medicine_List.setAdapter(adapter);
           medicine_List.setOnItemClickListener(this);

    }

And this is the method for reading data from SQLite!

public ArrayList getStoreName(long storeId) {
        ArrayList<String> array_list = new ArrayList<String>();
        String[] column2 = new String[] { AREA_PREV_ID, STORE_NAME };
        Cursor res = ourDatabase.query(DATABASE_TABLE2, column2, AREA_PREV_ID + "=" + storeId, null, null, null, null);
        int istore = res.getColumnIndex(STORE_NAME);
        if (res != null) {
            res.moveToFirst();
          while(res.isAfterLast() == false){
              String s = res.getString(istore);
          array_list.add(s);
          res.moveToNext();
          }
        }
        return array_list;
    }

Can anyone help what m i doing wrong here!Thanks in advance

来源:https://stackoverflow.com/questions/26755514/list-items-not-showing-when-reading-data-from-sqlite-db

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