问题
I am new to Android and Java development
and I am wondering how to make the buttons in the dashboard open the same activity but with different data
for each fragment . this activity will work the same way for all the buttons the only thing changing is the sortalgorithm.java
used
回答1:
you can put a flag in your intent when you call startActivity(Intent intent) method. is something like this:
//...
Intent intent = new Intent(this, DisplayMessageActivity.class);
Bundle b = new Bundle();
b.putString("whatFragment","1");
intent.putExtra("extras",b);
startActivity(intent);
Then you catch this in your Fragment with:
/*
.
.
.
*/
Bundle b = getIntent().getExtras();
String whatFrag=b.getString("extras");
if(whatFrag.equals("1")){
//code if fragment selected is 1
}
/*
.
.
.
*/
来源:https://stackoverflow.com/questions/61071427/how-to-make-multiple-buttons-open-the-same-activity