我想在listview点击事件&上更改Textview Color和Imageview图像我也创建自定义列表视图。我希望当我点击列表视图项目来更改图像和文本颜色并转到另一个活动,但当我返回列表活动并单击其他列表项目来更改文本颜色和图像以及更改首先单击项目颜色和图像..我的代码如下:
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);
}
});
答案 0 :(得分:0)
只需添加到您的清单(此活动):
android:launchMode="singleTask"
或:
android:launchMode="singleInstance"
您的活动将不再重新开始。它会被保存。
更多信息:here
答案 1 :(得分:0)
声明:
SharedPrefernces mPrefs;
in on create:
mPrefs = getSharedPreferences("some name", 0);
使用值:
int value = mPrefs.getInt("value name",0);
以节省价值:
mPrefs.edit().putInt("value name",value);
mPrefs.edit().commit();