`

extends ListActivity

 
阅读更多



 

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
分享到:
评论

相关推荐

    android listview 上下滑动刷新

    public class PullToRefreshActivity extends ListActivity { private LinkedList, String&gt;&gt; mListItems; private NewsAdapter adapter; private int lastItem; @Override public void onCreate(Bundle ...

    Android-ListActivity实现列表[汇编].pdf

    public class MainActivity extends ListActivity { private String data[][]=new String[][]{{"01","张博涵 "},{"02","8岁"},{"03","三八班 "},{"04","喜爱玩游戏 "}}; private List,String&gt;&gt; list=new ArrayList...

    Android资料

    public class MainActivity extends ListActivity implements OnItemClickListener { // private ListView lv; private String[] numbers = {"1", "2", "3", "4", "5", "6" ,"7"};//①先定义一个数组 private ...

    Android课件

    public class TestFilter extends ListActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ...

    android adapter详解

    public class CustomAdapterActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); ArrayList...

    listViewSample_android_

    public class MainActivity extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] items = {"Item 1", "Item 2", "Item 3...

    ListView的两种实现方法

    public class ListActivityExample extends ListActivity { private String[] items = {"Item 1", "Item 2", "Item 3"}; // 示例数据 @Override protected void onCreate(Bundle savedInstanceState) { super....

    Android学习笔记(十一):Activity-ListView.doc

    public class BeginingBook extends ListActivity { String[] items = {"One", "Two", "Three", "Four", "Five", "Six", "Seven"}; @Override public void onCreate(Bundle savedInstanceState) { super....

    ListAcitivity自定义样式

    public class CustomListActivity extends ListActivity { private ArrayList&lt;String&gt; dataList; private CustomAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super....

    订餐系统的android版本

    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"}; ...

    解析m3u播放列表对应的音乐文件

    public class InternetAudioDemo extends ListActivity { private Button btnParse, btnPlay, btnStop; private EditText editUrl; private MediaPlayer player; private List&lt;String&gt; pathList; private int ...

    Android学习笔记(十七):再谈ListView.doc

    public class Chapter8Test2 extends ListActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.chapter_8_test2); ...

    android 图片浏览器,代码及详细步骤

    public class FileListActivity extends ListActivity { // ...其他代码... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); rootFile = Environment....

    Android应用程序之间数据共享—ContentResolver(1)[定义].pdf

    public class showcontact extends ListActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Cursor c = getContentResolver().query(Phones.CONTENT_URI, ...

    Android MediaPlayer 简单综合应用.doc

    public class MeusicDemo extends ListActivity { private static final String MEDIA_PATH = "/sdcard/"; private MediaPlayer mediaPlayer; private ArrayList&lt;String&gt; songsList = new ArrayList(); @...

    android Adapter教程

    public class ArrayAdapterActivity extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String[] strs = {"1", "2", "3", "4", "5"};...

    ListView 详解

    public class MyListView3 extends ListActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SimpleAdapter adapter = new SimpleAdapter( this, ...

    Android学习笔记(三二):线程:后台异步任务AsyncTask_IT168文库

    public class Chapter15Test3 extends ListActivity { // ListItem内容,在这个例子中,将在后台任务中逐个加入 private static String[] items = {"lorem", "ipsum", "dolor", "sit", "amet", "consectetuer", ...

Global site tag (gtag.js) - Google Analytics