请指导我使用此程序。为什么我们需要使用阵列适配器来显示列表?这个“适配器”是什么,我们可以直接在ListView中显示东西,而无需适配器?像,我们可以设置setListAdapter(名称),而不是setListAdapter(适配器);?谢谢。
下面是代码:列表视图适配器
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class Episode7 extends ListActivity {
String[] names = {
"Elliot","Geoffrey","Samuel","Harvey","Ian","Nina","Jessica",
"John","Kathleen","Keith","Laura","Lloyd"
};
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Create an ArrayAdapter that will contain all list items
ArrayAdapter<String> adapter;
/* Assign the name array to that adapter and
also choose a simple layout for the list items */
adapter = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
names);
// Assign the adapter to this ListActivity
setListAdapter(adapter);
}
}