WEB开发网
开发学院手机开发Android 开发 ListView 控件常规用法 阅读

ListView 控件常规用法

 2010-09-27 02:01:00 来源:WEB开发网   
核心提示:< TextViewandroid:text="TextView02"android:layout_height="wrap_content"android:layout_width="fill_parent"android:layout_below=&

< TextView

android:text="TextView02"

android:layout_height="wrap_content"

android:layout_width="fill_parent"

android:layout_below="@+id/ItemTitle"

android:id="@+id/ItemText"

/>

< /RelativeLayout>

最后在Activity里面调用和加入Listener,具体见注释:

package com.ray.test;

import java.util.ArrayList;

import java.util.HashMap;

import android.app.Activity;

import android.os.Bundle;

import android.view.ContextMenu;

import android.view.MenuItem;

import android.view.View;

import android.view.ContextMenu.ContextMenuInfo;

import android.view.View.OnCreateContextMenuListener;

import android.widget.AdapterView;

import android.widget.ListView;

import android.widget.SimpleAdapter;

import android.widget.AdapterView.OnItemClickListener;

public class TestListView extends Activity {

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

//绑定Layout里面的ListView

ListView list = (ListView) findViewById(R.id.ListView01);

//生成动态数组,加入数据

ArrayList< HashMap< String, Object>> listItem = new ArrayList< HashMap< String, Object>>();

for(int i=0;i< 10;i++)

{

HashMap< String, Object> map = new HashMap< String, Object>();

map.put("ItemImage", R.drawable.checked);//图像资源的ID

map.put("ItemTitle", "Level "+i);

map.put("ItemText", "Finished in 1 Min 54 Secs, 70 Moves! ");

listItem.add(map);

}

//生成适配器的Item和动态数组对应的元素

SimpleAdapter listItemAdapter = new SimpleAdapter(this,listItem,//数据源

Tags:ListView 控件 常规

编辑录入:coldstar [复制链接] [打 印]
赞助商链接