如何使多个按钮打开同一活动? [英] How to make multiple buttons open the same activity?
本文介绍了如何使多个按钮打开同一活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Android和Java开发的新手
而且我想知道如何使仪表板中的按钮打开相同的活动但使用不同的数据
对于每个片段.此活动对所有按钮都将以相同的方式工作,唯一的变化是sortalgorithm.java
使用
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
推荐答案
您可以在调用startActivity(Intent intent)方法时在目标中放置一个标志.是这样的:
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
}
/*
.
.
.
*/
这篇关于如何使多个按钮打开同一活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文