Add Items to ListView - Android

后端 未结 3 801
终归单人心
终归单人心 2020-12-05 11:16

This is my first experience with android. I\'m trying to add items to my ListView. I use Tabs, and the only way to see that the item was added is to change tab and then come

3条回答
  •  情书的邮戳
    2020-12-05 11:56

    Try this one it will work

    public class Third extends ListActivity {
    private ArrayAdapter adapter;
    private List liste;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_third);
         String[] values = new String[] { "Android", "iPhone", "WindowsMobile",
                    "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X",
                    "Linux", "OS/2" };
         liste = new ArrayList();
         Collections.addAll(liste, values);
         adapter = new ArrayAdapter(this,
                    android.R.layout.simple_list_item_1, liste);
         setListAdapter(adapter);
    }
     @Override
      protected void onListItemClick(ListView l, View v, int position, long id) {
         liste.add("Nokia");
         adapter.notifyDataSetChanged();
      }
    }
    

提交回复
热议问题