Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9092163
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:46:33+00:00 2026-06-16T22:46:33+00:00

I am trying to display a long string into multiple pages. My Activity.xml has

  • 0

I am trying to display a long string into multiple pages. My Activity.xml has a textview which occupies 90% of the height of screen(this is ow I have set the relativelayout). I need some help in finding out the right methods/classes I can use to acheive my objective

Below is my code. The content in bold (comment starting with ** down in the code) is where I need help.

public class StoryActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_story);

    String contentString;
    String pageString;
    final int screenWidth;
    final int screenHeight;
   final int pageWidth;
   final int pageHeight;
   final int totalPages;
   int pageNumber;


    //load the content into the string contentString    
    InputStream is = getAssets().open("Story.txt");
        int size = is.available();
       byte[] buffer = new byte[size];
       is.read(buffer);
       is.close();
     contentString = new String(buffer);

           // get screen dimensions       
       DisplayMetrics dm = new DisplayMetrics();
       getWindowManager().getDefaultDisplay().getMetrics(dm);
       screenWidth = dm.widthPixels;
       screenHeight= dm.heightPixels;

       // create textview
       TextView tv = (TextView)findViewById(R.id.textViewStory);

             // calculate pageheight since textview size is 90% of the screen 
            pageHeight = (int) (0.9* screenHeight);
            pageWidth = screenWidth;

            **// 1)need to find number of lines which will fit pageHeight
            // 2)then I need to find total number of lines in my String contentString
            // 3)dividing 2) by 1) can give me number of pages required to display 
            // contentString. 
            // 4)I can then concatenate contentString at number of lines as found in 
            // 1) and thus I know what text (pageString) to display in page1**

            tv.setText(pageString); 

            **// steps 4) can be repeated to display next page when user click 
            // “nextpage” button**         

    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:46:35+00:00Added an answer on June 16, 2026 at 10:46 pm

    I will not provide you full solution but I’ve found answers that can help you.

    1. First helps to find how many characters can feet in TextView width.
    2. Second helps to get how many lines TextView exactly shows.

    But there is problem with line wrapping. You need to apply some algorithm to find out how text is wrapped by android framework or do this for it. Here is good answer for text wrapping

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to display a time difference into a string which follows the
I'm trying to display string on the textview. I'm succesfully able to print it
I'm trying to figure out the best way to display a long list of
I am trying to write a long string in Python that gets displayed as
I am trying to display sig figs in a string and I have found
I have a TextView that I am trying to make display a 2d character-based
I was able to turn a long string into a dl list as shown
I develop a widget on Android which display many useful informations. I am trying
I am trying to display numbers in a string dynamically, so if the number
I am trying to display string array in JSP page. I have got a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.