java - how to save a dynamic string? -
in app current time , convert string.
as see string changed every time open activity want save time string in static string if went activity show user.
this code far:
time = new time(); now.settonow(); string str = now.tostring().substring(0, 15); textview.settext(str);
actually have listview has items. time string in listview.onitemclicklistener
, want whenever item created save time , when users clicked on show time in second activity.
example if user created item in listview in 2 days ago, when clicks on item show 2 days ago date , time:
this code more details:
first activity:
list.setonitemclicklistener(new onitemclicklistener() { @override public void onitemclick(adapterview<?> arg0, view arg1, int arg2, long arg3) { time = new time(); now.settonow(); string timedate = now.tostring().substring(0, 15); intent intent = new intent(albums.this, albumpage.class); intent.putextra("extra", timedate); startactivity(intent); }
second activity:
string str = getintent().getextras().getstring("extra"); textview.settext(str);
in way when click on each item shows current time not time item created (my listview dynamic user can add or delete items).
try below code:
sharedpreferences sharedpreferences = getsharedpreferences("myprefs", context.mode_private); editor editor = pref.edit(); time = new time(); now.settonow(); string str = now.tostring().substring(0, 15); editor.putstring("key_name", str); editor.commit(); textview.settext(str);
Comments
Post a Comment