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

  • SEARCH
  • Home
  • 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 6937753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:24:16+00:00 2026-05-27T12:24:16+00:00

I have an app for a project. my idea was to create a 3

  • 0

I have an app for a project. my idea was to create a 3 tab app, in each tab there are several buttons representing a topic. each topic has a txt file containing some information I wish to display in an activity that is opened when clicking a particular button. so the same activity is opened, but the text filling it will depend on the button pressed.

I have everything except the ability to display the text, currently stored in /raw as a txt.

I’m looking at input readers and txt vs xml (former seems easier), and I’m still struggling.

Even if I manage to get it to display a particular txt file, I don’t know how to get it to work dependant on which button is pressed.

The content holding activity has a textview which I planned to fill with text from the .txt file.

Any help would be appreciated.

I get a syntax error on that catch. spent the last 15 minutes trying to figure it out

EDIT

activity with buttons in it,

public class MartialTab extends Activity {
Button btn1, btn2;
String choice;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    TextView textview = new TextView(this);
    textview.setText("This is the martial arts tab");
    setContentView(textview);

    setContentView(R.layout.martial_tab);//takes layout from martial_tab.xml

    btn1 = (Button) findViewById(R.id.kickboxingButton);//instantiates a button called btn1 one from the xml
    btn1.setOnClickListener( new OnClickListener() {
        public void onClick(View v) {
            kickBoxingBut(v, choice);
        }//calls the method
    });//end of method

    btn2 = (Button) findViewById(R.id.grecoroman);//instantiates a button called btn1 one from the xml
    btn2.setOnClickListener( new OnClickListener() {
        public void onClick(View v) {
            grecoromanBut(v);
        }//calls the method
    });//end of method


}



  // private void kickBoxingBut() {//button1 method
    //new AlertDialog.Builder(this).setTitle("AlertNotification").setMessage(
       // "This is an Alert Dialogue Toast").setNeutralButton( "Click Me!", null).show(); 
    //creates an alert notification with the above text
  //}
    public   String kickBoxingBut(View view, String s) { 
        startActivity(new Intent(this, ContentHolder.class));
        this.choice = "kick";

        return choice;

    }

    public void grecoromanBut(View view) { 
        startActivity(new Intent(this, ContentHolder.class));
    }       
}

activity that holds the info

     public class ContentHolder extends Activity  {



    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    Context m_Context = getApplicationContext();

    TextView textview = new TextView(this);
    textview.setText("This is the content view");
    setContentView(textview);

    Bundle extras = getIntent().getExtras(); 
    if(extras !=null) {
    String value = extras.getString("choice");
    }



    InputStream input;

    try {
        input = m_Context.getAssets().open("choice");

    DataInputStream in = new DataInputStream(input);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    // Read File Line By Line
    while ((strLine = br.readLine()) != null) {
        // Print the content on the console
        System.out.println(strLine);
        textview.setText(strLine);
    }
    // Close the input stream
    in.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    }
    //setContentView(R.layout.main);

   }

This setContentView is a problem. As above doesn’t work as it expects a return type. changing it to ContentHolder doesn’t work either.

  • 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-05-27T12:24:17+00:00Added an answer on May 27, 2026 at 12:24 pm

    You can open an asset txt file and read line by line like this:

    InputStream input = context.getAssets().open(fileName);
    DataInputStream in = new DataInputStream(input);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    //Read File Line By Line
    while ((strLine = br.readLine()) != null)   {
        // Print the content on the console
        System.out.println (strLine);
    }
    //Close the input stream
    in.close();
    } catch (Exception e){//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
    

    This is a good start for you, display the lines you read in a TextView. Once you do this, you can move on to next step.

    EDIT

    package com.example.helloandroid;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.widget.TextView;
    
    public class HelloAndroid extends Activity {
       /** Called when the activity is first created. */
       @Override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
    
           // This is how you get the context
           Context m_Context = getApplicationContext();
    
           // This is how you show text programatically, there is also xml option, which I recommend instead.
           TextView tv = new TextView(this);
           tv.setText("Hello, Android");
           setContentView(tv);
    }
    

    http://developer.android.com/resources/tutorials/hello-world.html

    EDIT2

    public class ContentHolder extends Activity {
    
        String fileName;
    
        public void onCreate(Bundle savedInstanceState) {
    
        super.onCreate(savedInstanceState);
        Context m_Context = getApplicationContext();
    
        TextView textview = new TextView(this);
        textview.setText("This is the content view");
    
        InputStream input;
        try {
            input = m_Context.getAssets().open(fileName);
    
        DataInputStream in = new DataInputStream(input);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        // Read File Line By Line
        while ((strLine = br.readLine()) != null) {
            // Print the content on the console
            System.out.println(strLine);
            textview.setText(strLine);
        }
        // Close the input stream
        in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        }
    
        setContentView(R.layout.main);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create CMakeLists.txt file for KDE4/Qt4 project. In this project currently there
I have a project where I have multiple instances of an app running, each
I have a .net interop project that uses an app.config file. When I am
I have a little pet web app project I'd like to show someone who
I have a very complex web app project I want to re-structure. Naturally, it
I have UITableViewController (initiated by the Navigation-based app project template). I am overriding loadView
In my project (iPhone app) I have a nice webview to allow users to
When I have one app.config in my main project I always have to duplicate
I'm trying to bind in a third party app to our project but have
I have a setup project that installs my app to the typical program files

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.