Waz*_*_Be 40 android button android-activity
我目前有一些带按钮的活动.
在我的xml中,按钮的定义如下:
<ImageButton (...) android:onClick="GoToPageX"/>
Run Code Online (Sandbox Code Playgroud)
我有我的活动:
public void GotoPageX() {
startActivity(new Intent(this, PageX.class));
finish();
}
Run Code Online (Sandbox Code Playgroud)
问题是我有数百个按钮,不想写
<ImageButton (...) android:onClick="GoToPage1"/>
<ImageButton (...) android:onClick="GoToPage2"/>
<ImageButton (...) android:onClick="GoToPage3"/>
...
<ImageButton (...) android:onClick="GoToPage100"/>
Run Code Online (Sandbox Code Playgroud)
和所有脚本.
我现在正在使用
public void GotoPage( int i) {
startActivity(new Intent(getBaseContext(), activities.get(i)));
finish();
}
Run Code Online (Sandbox Code Playgroud)
并且想从xml中给出参数i,这可能吗?
非常感谢任何帮助.
Ocu*_*cuS 96
这不是直接可能的.但是,也许您可以使用android:tag
获取参数.
<ImageButton (...) android:onClick="goToPage" android:tag="25"/>
public void goToPage(View v) {
String pageNumber = v.getTag().toString();
/* ... */
}
Run Code Online (Sandbox Code Playgroud)