Android Programming
This may s开发者_如何学运维eem like a dumb question, but do you need an xml and class for every activity aka. page you want in an app. The more activities I have, the slower the emulator is. I want to create a reference app much like Human Japanese, and was wondering how to create multiple pages in an app without creating multiple activities.
Tabs allow you to have multiple full screen views in a single Activity.
When I was creating my OSCAR 2011 app, I had this question. What I did was I passed a value along with Intend and received passed value in the activity class which initiated by the Intend. based on the value recieved I can call different values from string xml file.
this is how it is in the class where call originated.
case 0:
Intent bestactor = new Intent(MovieList.this,WinnerActivity.class);
bestactor.putExtra("ListCount", "one");
startActivity(bestactor);
break;
This is how I received and set the content
Bundle extras = getIntent().getExtras();
String data = extras.getString("ListCount");
if(data.equals("one"))
{
setContentView(R.layout.winner);
TextView txtWinnerList = (TextView) findViewById(R.id.txtWinnerList);
txtWinnerList.setText(R.string.actorintheleadingrole);
TextView txtNomineeList = (TextView) findViewById(R.id.txtNomineesList);
txtNomineeList.setText(R.string.nomineesactorinleadingrole);
}
else if(data.equals("two"))
{
setContentView(R.layout.winner);
TextView txtWinnerList = (TextView) findViewById(R.id.txtWinnerList);
txtWinnerList.setText(R.string.actorinasupportingrole);
TextView txtNomineeList = (TextView) findViewById(R.id.txtNomineesList);
txtNomineeList.setText(R.string.nomineesactorinasupportingrole);
}
It gets messy but you could have as many sibling full screen layouts at the top level as you want that you show and hide as necessary. So you can simulate as many activities as you like all within one.
You can do setVisible true or false in every view of your Activity. This let's you to change the information completely without change the Activity. I've used this with succeed.
精彩评论