I have a list view, how can I save a list view total number of clicks to another activity text view?
I have custom list view, it has money TextView and a name TextView. When I clicked on list view total number of clicks save on another activity text view.
example like..
list view item=5
1st item clicked->another activity text view have one value.
2nd item clicked->another activity text view have two value.(prevoius and new value)
Use can use SharedPreferences for this...
int count=0;
SharedPreferences pref=getSharedPreferences("share",1);
Editor edit=pref.edit();
if(pref.contains("count"))
{
count=pref.getInt("count", 0);
}
//Do this code in OnItemClickListener()..
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
count++;
edit.putInt("count", count);
edit.commit();
Intent intent=new Intent(getActivity(),PersonalChat.class);
startActivity(intent);
}
});
You can have a countClicks int in your activity and pass this int in the intent when you create the new Activity.
Catch the click like this :
int countClick = 0;
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
countClicks ++;
}
});
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.