Search code examples
androidlistviewlistviewitem

Populate listview with time by pressing a button in Android


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!


Solution

  • 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);
        }
    };