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 8607761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:26:25+00:00 2026-06-12T03:26:25+00:00

I am new to android/java and trying to learn by typing code from tutorials

  • 0

I am new to android/java and trying to learn by typing code from tutorials. I’m trying to see if I can make a FAQs android module.
Could someone show me how to display only the list of questions and when you click on a question, correspond question and answer display on the next activity?
It’s currently displaying both question and answer for the both activities.

Hope my question makes sense. please kindly ask and I will explain as best as I can.

Thank you very much!

faq_list.xml

<item>      
    <id>1</id>
    <question>Whats my phone number?</question>
    <answer>my phone number here</answer>        
</item>  

<item>      
    <id>2</id>
    <question>Whats my fax number?</question>
    <answer>my fax number here</answer>        
</item>  

<item>      
    <id>3</id>
    <question>What is my mailing address?</question>
    <answer>my address here</answer>        
</item>  

faqs_questions.xml

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <!-- qnestion -->
        <TextView
            android:id="@+id/question"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#000"
            android:textSize="14sp"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:layout_weight="1"
            android:paddingLeft="5sp" />
        <!-- answer  --> 
        <TextView
            android:id="@+id/answer"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#000"
            android:textSize="14sp"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:layout_weight="2"
            android:paddingLeft="5sp">
        </TextView>     

        </LinearLayout>

faqs_answers.xml

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:background="#fff"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <TextView android:id="@+id/question_label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="14dip"       
            android:textStyle="bold"     
            android:textColor="#000"            
            android:paddingLeft="5sp"
            /> 

  <TextView android:id="@+id/answer_label"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textSize="14dip"       
            android:textColor="#000"            
            android:paddingLeft="5sp"
            />

</LinearLayout>

FaqsQuestionsActivity.java

    public class FaqsQuestionsActivity extends ListActivity {


    static final String URL = "http://myweb.com/faq_list.xml";
    // XML node keys
    static final String KEY_ITEM = "item"; // parent node   
    static final String KEY_ID = "id";
    static final String KEY_QUESTION = "question";
    static final String KEY_ANSWER = "answer";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.faqs_questions);

        ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

        XMLParser parser = new XMLParser();
        String xml = parser.getXmlFromUrl(URL); // getting XML
        Document doc = parser.getDomElement(xml); // getting DOM element

        NodeList nl = doc.getElementsByTagName(KEY_ITEM);

        for (int i = 0; i < nl.getLength(); i++) {

            HashMap<String, String> map = new HashMap<String, String>();
            Element e = (Element) nl.item(i);

            map.put(KEY_ID, parser.getValue(e, KEY_ID));
            map.put(KEY_QUESTION, parser.getValue(e, KEY_QUESTION ));
            map.put(KEY_ANSWER, parser.getValue(e, KEY_ANSWER));

            menuItems.add(map);
        }

        ListAdapter adapter = new SimpleAdapter(this, menuItems, R.layout.faqs_question_list,
        new String[] { KEY_QUESTION, KEY_ANSWER  }, new int[] {R.id.question, R.id.answer});


        setListAdapter(adapter);

        ListView lv = getListView();

        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {


                String question = ((TextView) view.findViewById(R.id.question)).getText().toString();
                String answer = ((TextView) view.findViewById(R.id.answer)).getText().toString();


                Intent in = new Intent(getApplicationContext(), FaqsAnswersActivity.class);

                in.putExtra(KEY_QUESTION, question);
                in.putExtra(KEY_ANSWER, answer);
                startActivity(in);

            }
        });
    }
}

FaqsAnswersActivity.java

public class FaqsAnswersActivity  extends Activity {

    // XML node keys

    static final String KEY_QUESTION = "question";
    static final String KEY_ANSWER = "answer";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.faqs_answers);

        // getting intent data
        Intent in = getIntent();

        // Get XML values from previous intent
        String question = in.getStringExtra(KEY_QUESTION);
        String answer = in.getStringExtra(KEY_ANSWER);

        // Displaying all values on the screen        
        TextView lblQuestion = (TextView) findViewById(R.id.question_label);
        TextView lblAnswer = (TextView) findViewById(R.id.answer_label);        

        lblQuestion.setText(question);
        lblAnswer.setText(answer);


    }
}
  • 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-12T03:26:26+00:00Added an answer on June 12, 2026 at 3:26 am

    It looks to me like the previous answer may give you a problem since you are pulling values from your TextView to put in the Intent for the next Activity.

    Instead, I suggest that you change the visibility of your answer TextView in “questions.xml” like this:

    <TextView
            android:id="@+id/answer"
            android:visibility="gone"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textColor="#000"
            android:textSize="14sp"
            android:layout_marginBottom="10dip"
            android:layout_marginTop="10dip"
            android:layout_weight="2"
            android:paddingLeft="5sp">
    </TextView>  
    

    Also, since the view is not visible, you could remove the layout properties that are now irrelevant. I believe all you should need is id and visibility.

    <TextView
            android:id="@+id/answer"
            android:visibility="gone">
    </TextView> 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android/java and currently am trying to learn custom events and
I'm learning android and java and am trying to learn how to make a
I'm trying to learn some Android and java programming in Eclipse. I can run
I'm very very new to android & JAVA, and I'm trying to learn writing
I am a little new to android/java. I am trying to pass JSON values
I'm still new to programming/Java/Android so I'm trying to understand everything I do and
First of all, I'm quite new to the Android and JAVA world (coming from
I'm new to android... having trouble trying to open a URL from a live
I'm new to Android development in Java and Eclipse. I am trying to develop
I am trying to make an Android/ Java application that needs to connect to

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.