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.
You should probably do:
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
idof the View is the proper way to do it. You were also not findingtextView2because it was in the other xml file.