第七篇-列表式App(ListActivity及ListView)

少年乘勇气,百战过乌孙。这篇文章主要讲述第七篇-列表式App:ListActivity及ListView相关的知识,希望能为你提供帮助。
一、新建一个empty activity的项目。
二、修改MainActivity.java:
extends AppCompactActivity改为extends ListActivity。注释掉setContentView(R.layout.activity_main);

package com.example.aimee.listapp; import android.app.ListActivity; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; public class MainActivity extends ListActivity { //Step 1 - define data - string array String data[] = { "Apple", "Samsung", "Huawei", "Xiaomi", "HTC", "LG", "Dummy", "Dummy", "Dummy", "Dummy", "Dummy", "Dummy", "Dummy", "Dummy", "Dummy", "LAST item" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //setContentView(R.layout.activity_main); //Step 2 - Define array adapter ArrayAdapter< String> adapter=new ArrayAdapter< String> ( this, android.R.layout.simple_list_item_1, android.R.id.text1, data ); //Step 3 - update adapter setListAdapter(adapter); }//@Override //protected void onListItemClick(ListView l, View v, int position, long id) { //super.onListItemClick(l, v, position, id); ////Create Intent // ////JUmp to anather activity //} }

【第七篇-列表式App(ListActivity及ListView)】

    推荐阅读