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)); } @Override protected void onListItemClick(ListView l, View v, int position, long id) { // TODO Auto-generated method stub MyButton.setText(items[position]); super.onListItemClick(l, v, position, id); } }结果如图