I want to change Textview Color and Imageview image on listview click event & i also create custom listview .I want that when i click on a listview item to change image and text color and go to another Activity, but when i go back to list activity and click other list item to change textcolor and image as well as change first click item color and image..my code given below:
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);
}
});
Just add to your manifest (to this activity):
android:launchMode="singleTask"
or:
android:launchMode="singleInstance"
Your activity won't recreacte any more. It will be saved.
More info: here
declare:
SharedPrefernces mPrefs;
in on create:
mPrefs = getSharedPreferences("some name", 0);
to use value:
int value = mPrefs.getInt("value name",0);
to save value:
mPrefs.edit().putInt("value name",value);
mPrefs.edit().commit();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.