0

Can anyone explain how to achieve this requirement?

Here is my requirement:

  • I should be able to dynamically add new elements by pressing a button which shows the time when button is pressed.

I know this is the silly question, but i need to solve this problem. Please help. Thanks!

Mahesh Babariya
  • 4,560
  • 6
  • 39
  • 54

2 Answers2

1
button.setOnCLickListener(clickListener);

View.OnClickListener clickListener = new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        MyAdapter myAdapter = new MyAdaper(this, new ArrayList<>());
        myListView.setAdapter(myAdapter);
    }
};
Ihor Bykov
  • 1,843
  • 3
  • 15
  • 22
  • IgorB I know this method, but i need to add current time in the listview element – Mahesh Babariya Jan 05 '16 at 15:52
  • Some you have some model that you populate in ListView. At any time just go throw all element in adapter `mAdapter.getItem()` and update time what you want to populate. after this just call `mAdapter.notifyDataSetChanged();` – Ihor Bykov Jan 05 '16 at 16:15
0

You can do so by telling the adapter of the listview that the data has changed after adding the new element.

listView.getAdapter().notifyDataSetChanged();
Drilon Blakqori
  • 2,796
  • 2
  • 17
  • 25