android控件之ListView(一)

来源:互联网 发布:物流配货软件 编辑:程序博客网 时间:2024/04/26 08:32

main.xml

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <Button         android:id="@+id/myButton"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:text="点击"         />    <ListView         android:id="@android:id/list"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:drawSelectorOnTop="true"        /></LinearLayout>

android:drawSelectorOnTop="true" 点击某一条记录,颜色会显示在最上面,记录上的文字被遮住,所以点击文字不放,文字就看不到
android:drawSelectorOnTop="false" 点击某条记录不放,颜色会在记录的后面,成为背景色,但是记录内容的文字是可见的

MytestActivity.java

package com.android.demo;import android.app.ListActivity;import android.os.Bundle;import android.view.View;import android.widget.ArrayAdapter;import android.widget.Button;import android.widget.ListView;public class MytestActivity extends ListActivity {Button MyButton;String[] items={"One", "Two", "Three", "Four", "Five"};    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);                MyButton = (Button)findViewById(R.id.myButton);        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, items));    }@Overrideprotected void onListItemClick(ListView l, View v, int position, long id) {// TODO Auto-generated method stubMyButton.setText(items[position]);super.onListItemClick(l, v, position, id);}    }
结果如图


原创粉丝点击