0

I am developing a messaging app; all is going well and I am doing some research on how to add data to the ListView once the user receives a new message. From what I have gathered so far, the notifyDataSetChanged() function does this. The tutorial I have uses the function below to update data in the ListView.

private void addItemsToList() {  
       int randomVal = MIN + (int) (Math.random() * ((MAX - MIN) + 1));  
       mItems.add(String.valueOf(randomVal));  
       mListAdapter.notifyDataSetChanged();  
  }

As you can see, this will update a single value randomVal to the ArrayList. In a messaging scenario, the data to be updated includes the message, sender username and time of sending the message.

My question is, will the above function add more than one item to the ListView Row and if not, what modifications should be made to enable it add more than one value to the ListView?

Biko
  • 332
  • 3
  • 15
  • You have to implement your own adapter: http://www.vogella.com/tutorials/AndroidListView/article.html – Héctor Jun 21 '16 at 10:56
  • use custom listview – kiran kumar Jun 21 '16 at 11:02
  • I have read that tutorial but it only addresses updating the ListView with one variable for each row...I want to add atleast 3 variables to a row @bigdestroyer – Biko Jun 21 '16 at 11:06
  • Already have a custom listView @kiran – Biko Jun 21 '16 at 11:07
  • First, you have to create a custom XML layout for each list item. Then, create a custom adapter (extends BaseAdapter) and in getView method, inflate the xml and bind your list item to the row view item – Héctor Jun 21 '16 at 11:08
  • Try this [tutorial](http://www.androidhive.info/2014/07/android-custom-listview-with-image-and-text-using-volley/) – kiran kumar Jun 21 '16 at 11:10
  • Possible duplicate of [Custom Adapter for List View](http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view) – Héctor Jun 21 '16 at 11:15
  • I have a custom view and custom adapter ready and working. All I want to know is how I can add multiple data to my custom view when the user receives a new message. Currently I am using refresh but I don want people to keep on clicking refresh – Biko Jun 21 '16 at 17:32
  • @kiran...the tutorial does not address my issue – Biko Jun 21 '16 at 17:33

0 Answers0