Favorites - How would I implement a favorites button so when it is pressed, the textView text is saved to an activity called favorites?

StackOverflow https://stackoverflow.com/questions/15774079

  •  31-03-2022
  •  | 
  •  

문제

I am creating an app with textView boxes. When a button is pressed the text changes using a random generator. How do I implement a favorite button so when it is pressed, a toast is created and the textView text is saved to an activity called favorites?

도움이 되었습니까?

해결책

I would save the "textView" content as a SharedPreference in the onClick() method of the Button.

When the user accesses the Favorites Activity, I would send the SharedPreference value to the other Activity via the Extras Bundle

Depending on where you have to manage the list of stored Favorite values and how many there are, you may have to use a database instead of SharedPreference.

다른 팁

For this what are intents made for...

say you want to send data from Activity A to B

1>then in A's oncreate() call this

Intent i = new Intent(this,your.class);
i.putExtra("key", value);
startActivity(i);

2>and in B's oncreate() use this

int value = getIntent().getExtras().getInt("key");

i guess you got what i meant...give it a try...

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top