ListView

一个非常好的ListView讲解文章,里面提到了listView中的按键响应

http://www.cnblogs.com/allin/archive/2010/05/11/1732200.html

 

ListView框架流程:

1、Activity显示主布局,发现包含ListView就绘制ListView

2、ListView绘制时会查找自己身上的Adapter,调用Adapter的getSize()取得行号,并逐行调用getView()取得“行view”并将其画出来。

3、Adapter负责将数据源与行界面相关联。

编程时可以倒着写:行界面,数据源,Adapter,ListView,Activity。

 

编写Activity的Layout界面,包含一个ListView

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ListView android:id="@+id/ListView01" android:layout_height="fill_parent" android:layout_width="fill_parent"></ListView> </LinearLayout>

2、在Activity中取得ListView并设置它的Adpther。

package fy.test; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; public class HellowListView extends Activity { static final String[] COUNTRIES = new String[] { "Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra" }; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ListView list = (ListView) findViewById(R.id.ListView01); list.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES)); } }

你可能感兴趣的:(android,ListView,String,layout,Class,encoding)