S
S
spartan212018-11-02 15:52:25
Java
spartan21, 2018-11-02 15:52:25

How to match records in ListView and database?

I can’t figure out how to match the id of the records in the ListView and in the database.

ArrayList<Map<String,Object>> data=new ArrayList<Map<String, Object>>(
                type.size());
        Map<String,Object>m;
        for (int i=0;i<type.size();i++){
            m=new HashMap<String, Object>();
            m.put("type", type.get(i));
            m.put("sum", sum.get(i));
            data.add(m);
        }

        //массив имен Spend, Profit
        String[]from={"type","sum"};
        int[] to={R.id.tvType,R.id.tvSum};

        SimpleAdapter simpleAdapter=new SimpleAdapter(this,data,R.layout.item1,from,to);

 lvData=(ListView)findViewById(R.id.lvData);
            lvData.setAdapter(simpleAdapter);
            lvData.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

I found the function hasStableIds()==true
It's not entirely clear to me how and where to connect it, I didn't find clear examples.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-11-08
@spartan21

Add an additional field to your Map, for example id, which will contain an identifier from the database. Then you can get your object by the record number from the ListView and from it the id of the record from the database

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question