我的一个活动中有一个动态生成的按钮列表,我想知道如何让其中一个按钮在单击时打开另一个活动并根据单击列表中的哪个按钮显示文本。
我使用 for 循环生成按钮(为了便于阅读,我在循环中省略了与 TextViews 相关的详细信息,它还使用了其他地方定义的一些变量)
for (int i = 0; i < N; i++) {
// create a new Button
final Button rowButton = new Button(this);
// Set properties of rowButton
rowButton.setText("See Recipe");
rowButton.setId(RecipeArray.get(i));
// add the Button to the LinearLayout
myLinearLayout.addView(rowButton);
// save a reference to the Button for later
myButtons[i] = rowButton;
}
这些按钮代表一个特定的配方,当单击它们时,它们应该将用户带到一个新的活动“HowToMake”并生成一个仅包含与该配方相关的信息的文本视图。它们存储在代码片段“myButtons[i] = rowButton”底部的数组中,但我不确定如何使用它。
谢谢你的帮助。