Hello, please tell me, I take the data from the database using the SimpleAdapter and display it in the ListView, then I add new data to the database, tell me how to update the data in the ListView.
- And how are changes made to the database? Any external toilets or from the application itself? - cy6erGn0m
- SqlDB dbh = new SqlDB (this); dbh.openDatabase (); dbh.exec ("INSERT INTO schet (_id, naimen, vid_schet) VALUES ('" + prefName + "'," "+ naimen.getText () +" ', "" + vid_schet.getSelectedItem () + "") ") ; - Fedor
- maybe the fact is that this is done from different classes? - Fedor
|
3 answers
The adapter needs to call the notifyDataSetChanged () method. As a result, the adapter must "re-read" the data.
|
I used this:
List<Phonebook> listOfPhonebook = new ArrayList<Phonebook>(); for(int i = 0; i < phones.length; i++) { listOfPhonebook.add(new Phonebook(phones[i],numbers[i])); } PhonebookAdapter adapter = new PhonebookAdapter(this, listOfPhonebook); list.setAdapter(adapter);
I took the read array, and in the cycle I filled them with the phone book sheets, then it to the adapter.
- I'm doing this like adapter12 = new SimpleAdapter (this, createSensorsList (), ndroid.R.layout.simple_list_item_2, new String [] {"title"}, new int [] {android.R.id.text1}); lv = (ListView) findViewById (R.id.listView1); lv.setAdapter (adapter12); - Fedor
|
It only helped me to create a new adapter after adding the data (to the point that just copying the code of your adapter to the place after, where you add the data). Also climbed the entire network)
|