Reputation: 53600
I have a long text that I want to show it page by page. For my first try, I created 10 activity and put some button that when user clicks On it, next activity shows.
I read somewhere that I can load all my text in one activity with using Intent. is it possible? How it is possible? I don't want user scroll the page.
Thanks
Upvotes: 1
Views: 919
Reputation: 2146
Let's say you have your activity called MyTextActivity
, then in your button click listener, you pass on the text you want into an intent to your activity:
Intent i = new Intent(this, MyTextActivity.class);
i.putExtra("myText", "this is the text you want to display in the next page");
startActivity(i);
Then in your MyTextActivity
, you put the following in onCreate()
:
String textToDisplay = "";
Bundle extras = getIntent().getExtras();
if (extras != null){
textToDisplay = extras.getString("myText");
}
then you set your TextView text to this text.
Upvotes: 1
Reputation: 3757
I think the answer is "don't do this". Android runs on a variety of devices, and you should handle the cases where it won't fit on the screen that matches the device you're using for testing. Consider tablets, for example.
Upvotes: 0
Reputation: 13960
If the text is static,you can put it in a string resource and access it in all your activities. Otherwise, you can attach the string to the intent, using putExtra
.
Upvotes: 0
Reputation: 39807
Assuming you already have a TextView and a Button in your activity, when the Button is pressed you do not need to go to a new activity. Instead, you can change the content of your existing text view. Just use TextView.setText() to change it.
Upvotes: 0