我的应用程序代码中有一个ListView
,当点击它时使用一个AdapterView.OnItemClickListener
来检测点击。问题是,当我单击一个项目时,该项目的背景变为白色,而不是默认的橙色。像这样:
另外,当我不使用 AdapterView 时,点击的项目会变成橙色,没有任何问题。如何使单击项目的背景再次变为橙色?
编辑:
列表布局:main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:background="#00000000">
<!-- ListView (grid_items) -->
<ListView android:id="@+id/listview"
android:layout_height="fill_parent"
android:textSize="15px"
android:layout_width="fill_parent"
android:background="#00000000">
</ListView>
</RelativeLayout>
创建():
public void onCreate(Bundle savedInstanceState) {try{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
lv= (ListView)findViewById(R.id.listview);
lv.setBackgroundColor(Color.TRANSPARENT);
lv.setCacheColorHint(Color.TRANSPARENT);
//......calculations
for(int q = 0; q <v; q++){
HashMap<String, String> map = new HashMap<String, String>();
map.put("col_1", array[q]);
fillMaps.add(map);
lv.setOnItemClickListener(onListClick);
}
//......calculations
}
适配器视图:
private AdapterView.OnItemClickListener onListClick=new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView<?> parent,View view, int position, long id)
{
lv.setBackgroundColor(Color.TRANSPARENT);
lv.setCacheColorHint(Color.TRANSPARENT);
//.....calculations
}
正在使用的自定义主题:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="CustomWindowTitleBackground">
<item name="android:background">#323331</item>
</style>
<style name="CustomTheme" parent="android:Theme">
<item name="android:windowTitleSize">35dip</item>
<item name="android:windowTitleBackgroundStyle">@style/CustomWindowTitleBackground</item>
</style>
</resources>