package com.epoint.listview;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class Main extends ListActivity {
/**
* 注意本程序没有按通常的写法为Activity加载一个布局文件,
* 而是通过setListAdapter(adapter)自动添加一个ListView填充整个ListActivity
*
*/
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTitle("最简单的ListView");
String[] numbers = new String[] { "Zero", "First", "Scound", "Three",
"Four", "Five", "Six", "Seven", "Seven", "Seven" };
/**
* 第一个参数:当前的上下文
* 第二个参数:每个列表项的布局文件
* 第三个参数:参数
* Tip:你可以使用android.R.layout.simple_list_item_1代替R.layout.list_item,改变ListView显示的样式
*/
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.list_item, numbers);
setListAdapter(adapter);// 将adapter放入ListView中
ListView listview = getListView();
/**
* The setTextFilterEnabled(boolean) method turns on text filtering for
* the ListView, so that when the user begins typing, the list will be
* filtered.不太明白什么意思?
*/
listview.setTextFilterEnabled(true);
// 设置ListView的监听事件
listview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String s = ((TextView) view).getText().toString();
Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT)
.show();
}
});
}
}
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp" android:textSize="16sp"/>
- 大小: 16.7 KB
- 大小: 19.4 KB
分享到:
相关推荐
public class PullToRefreshActivity extends ListActivity { private LinkedList, String>> mListItems; private NewsAdapter adapter; private int lastItem; @Override public void onCreate(Bundle ...
public class MainActivity extends ListActivity { private String data[][]=new String[][]{{"01","张博涵 "},{"02","8岁"},{"03","三八班 "},{"04","喜爱玩游戏 "}}; private List,String>> list=new ArrayList...
public class MainActivity extends ListActivity implements OnItemClickListener { // private ListView lv; private String[] numbers = {"1", "2", "3", "4", "5", "6" ,"7"};//①先定义一个数组 private ...
public class TestFilter extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...
public class CustomAdapterActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList...
public class MainActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] items = {"Item 1", "Item 2", "Item 3...
public class ListActivityExample extends ListActivity { private String[] items = {"Item 1", "Item 2", "Item 3"}; // 示例数据 @Override protected void onCreate(Bundle savedInstanceState) { super....
public class BeginingBook extends ListActivity { String[] items = {"One", "Two", "Three", "Four", "Five", "Six", "Seven"}; @Override public void onCreate(Bundle savedInstanceState) { super....
public class CustomListActivity extends ListActivity { private ArrayList<String> dataList; private CustomAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super....
public class LookActivity extends ListActivity{ private String data[][] = { { " 座号:"," "+IndentData.num}, { " 产品", " 个数 单价" }, { "牛肉蛋花油条餐", "--------"+IndentData.fool_01+"-------...
public class MyListActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] items = {"App1", "App2", "App3"}; ...
public class InternetAudioDemo extends ListActivity { private Button btnParse, btnPlay, btnStop; private EditText editUrl; private MediaPlayer player; private List<String> pathList; private int ...
public class Chapter8Test2 extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chapter_8_test2); ...
public class FileListActivity extends ListActivity { // ...其他代码... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); rootFile = Environment....
public class showcontact extends ListActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor c = getContentResolver().query(Phones.CONTENT_URI, ...
public class MeusicDemo extends ListActivity { private static final String MEDIA_PATH = "/sdcard/"; private MediaPlayer mediaPlayer; private ArrayList<String> songsList = new ArrayList(); @...
public class ArrayAdapterActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] strs = {"1", "2", "3", "4", "5"};...
public class MyListView3 extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SimpleAdapter adapter = new SimpleAdapter( this, ...
public class Chapter15Test3 extends ListActivity { // ListItem内容,在这个例子中,将在后台任务中逐个加入 private static String[] items = {"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", ...