构造自己的adapter,在getView中,设置颜色,点击item,刷新listview。
代码:
import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.ListView; import android.widget.TextView; public class MyListView4 extends Activity { private List
其xml文件写法,同我的另一博文:
android 自定义adapter extends BaseAdapter,做有自己布局的listView
或:
siteListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent, View view,int position, long id) {
for(int i=0;i View v=parent.getChildAt(parent.getCount()-1-i);
if (position == i) {
v.setBackgroundColor(Color.RED);
} else {
v.setBackgroundColor(Color.TRANSPARENT);
}
}
}
});
屏蔽获取焦点时的高亮橙色显示:
listview.setSelector(R.drawable.nocolor);图片为一张无色透明图片即可,或者
android:listSelector="@drawable/nocolor"