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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:37:15+00:00 2026-06-16T12:37:15+00:00

attribute=(TextView) findViewById(R.id.textview1); dataAttribute=(TextView) findViewById(R.id.textview2); attribute.setClickable(true); attribute.setOnClickListener(this); dataattribute.setClickable(true); dataattribute.setOnClickListener(this); //dataAttribute.setOnClickListener(new OnClickListener(){ //@Override //public void onClick(View

  • 0
    attribute=(TextView) findViewById(R.id.textview1);
    dataAttribute=(TextView) findViewById(R.id.textview2);

            attribute.setClickable(true);
            attribute.setOnClickListener(this);


            dataattribute.setClickable(true);
            dataattribute.setOnClickListener(this);

    //dataAttribute.setOnClickListener(new OnClickListener(){

        //@Override
        //public void onClick(View v) {
            // TODO Auto-generated method stub
            //setContentView(R.layout.activity_main);
        //}
    //});
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
public void onClick(View v)
{

    if(v==attribute)
    {
        setContentView(R.layout.second_activity);
    }
    if(v==dataattribute)
    {
         setContentView(R.layout.main_activity);

    }
}

Sorry for the newbie question My problem is

There are two layout 1- main_activity.xml and 2- second_activity.xml
main_activity contains textview1 and second_activity contains textview2.
After clicking on first TextView set the Second layout but on clicking the second Text its not displaying the main_activity.xml layout.

  • 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-16T12:37:17+00:00Added an answer on June 16, 2026 at 12:37 pm

    You should probably do:

    public void onClick(View v)
    {
        switch (v.getId()){
        case R.id.textview1:
            setContentView(R.layout.second_activity);
            dataAttribute=(TextView) findViewById(R.id.textview2);
            dataAttribute.setClickable(true);
            dataAttribute.setOnClickListener(this);
    
            break;
        case R.id.textview2:
            setContentView(R.layout.main_activity);
            break;
        }
    }
    

    What you were doing before is comparing the references to the object, which under certain conditions might work (if the refereces are the same), but usually it doesn’t, so this causes logic issues. Comparing the id of the View is the proper way to do it. You were also not finding textView2 because it was in the other xml file.

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

Sidebar

Related Questions

I have a TextView in my layout which has an attribute clickable=true set in
Can this attribute be changed dynamically in Java code? android:layout_marginRight I have a TextView
The layout_weight attribute in the last TextView in this layout is being highlighted by
How can I make the textview wrap such text exactly ? android:width attribute is
I have this as part of my layout: <LinearLayout android:layout_width=fill_parent android:layout_height=0dip android:orientation=horizontal android:layout_weight=0.15> <TextView
I want to dynamically create a textview and set attributes. LinearLayout timeBar = (LinearLayout)findViewById(R.id.linear_layout_cells);
I am using antroid:autoLink=map attribute of TextView to Go to map and find the
Possible Duplicate: What means Ems? (Android TextView) In EditText there is an attribute named
I know how to do it programatically as such: TextView txt = (TextView) findViewById(R.id.custom_font);
I have a RelativeLayout where I have one TextView and this element has its

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.