[英]How to Handle Click on Imageview in Custom Listview with image and Textview?
[英]How to Change TextView color and ImageView Image on ListView Click event in Android?
我想在listview单击事件上更改Textview Color和Imageview图像&我还创建自定义listview。我希望当我单击listview项以更改图像和文本颜色并转到另一个活动时,但是当我返回到列表活动时并单击其他列表项以更改文本颜色和图像,以及更改以下单击项的颜色和图像..my代码如下:
SimpleAdapter adapter = new SimpleAdapter(getBaseContext(),
channel_listView, R.layout.listview_layout1, from, to);
listView.setDivider(null);
listView.setAdapter(adapter);
listView.setCacheColorHint(0);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
// TODO Auto-generated method stub
long c_name = listView.getItemIdAtPosition(position);
Log.i("c_name", "" + c_name);
((TextView) arg1.findViewById(R.id.txt))
.setTextColor(Color.YELLOW);
((ImageView) arg1.findViewById(R.id.flag))
.setBackgroundResource(R.drawable.yellowmusicicon);
String ch_name = (String) ((TextView) arg1
.findViewById(R.id.txt)).getText();
Log.i("txt_value", "" + ch_name);
Intent intent = new Intent(ChannelList.this,
FMActivity.class);
intent.putExtra("id", c_name);
intent.putExtra("c_name", ch_name);
startActivity(intent);
}
});
只需添加到您的清单(此活动):
android:launchMode="singleTask"
要么:
android:launchMode="singleInstance"
您的活动将不再活跃。 它将被保存。
更多信息: 这里
宣布:
SharedPrefernces mPrefs;
在创建时:
mPrefs = getSharedPreferences("some name", 0);
使用价值:
int value = mPrefs.getInt("value name",0);
节省价值:
mPrefs.edit().putInt("value name",value);
mPrefs.edit().commit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.