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
}
/*
.
.
.
*/