我应该在哪里对动态创建的android按钮进行编码,以及如何传递值';这是给听众的
因此,我正在创建动态分配的按钮。我想查询我的数据库,根据用户选择的表(即动态按钮),将打开一个新的活动,用户可以使用指定的表我应该在哪里对动态创建的android按钮进行编码,以及如何传递值';这是给听众的,android,button,android-intent,dynamic,onclicklistener,Android,Button,Android Intent,Dynamic,Onclicklistener,因此,我正在创建动态分配的按钮。我想查询我的数据库,根据用户选择的表(即动态按钮),将打开一个新的活动,用户可以使用指定的表 protected void createButtons(){ // dynamically created buttons work just need to LinearLayout scrViewButLay = (LinearLayout) findViewById(R.id.scrollViewLinLay); scrVi
protected void createButtons(){
// dynamically created buttons work just need to
LinearLayout scrViewButLay = (LinearLayout) findViewById(R.id.scrollViewLinLay);
scrViewButLay.removeAllViews();
ArrayList<String> tanks = new ArrayList<String>();
tanks = dbHand.getTableList();
Button[] tankButtons = new Button[tanks.size()];
Log.i("DB_Tag", "DB Size = " + tanks.size());
for(int i = 0; i < tanks.size(); i++){
Log.i("DB_NAME_TAG", tanks.get(i));
}
for (int index = 0; index < tanks.size(); index++) {
tankButtons[index] = new Button(this);
tankButtons[index].setText(tanks.get(index));
scrViewButLay.addView(tankButtons[index]);
tankButtons[index].setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Each buttons specific event
/*
* Left off here
*/
Intent intent = new Intent(MainAquariumActivity.this, ProfilesOptionsScreen.class);
startActivity(intent);
//How would I send tanks.get(index) to the new ProfilesOptionsScreen
}
});
}
// end of dynamically allocated buttons
}
受保护的void createButtons(){
//动态创建的按钮只需
LinearLayout scrViewButLay=(LinearLayout)findViewById(R.id.scrollViewLinLay);
scrViewButLay.removeAllViews();
ArrayList坦克=新的ArrayList();
tanks=dbHand.getTableList();
按钮[]坦克按钮=新按钮[tanks.size()];
Log.i(“DB_标签”,“DB Size=“+tanks.Size());
对于(int i=0;i
我假设您必须在创建按钮的同时动态创建onClickListeners。有更简单的解决方案吗?您应该使用AdapterView(ListView、GridView等)并用游标适配器填充它。如果您有一个示例,我将不胜感激。我正在研究AdapterView,看看如何将它应用到我的情况中。非常感谢@FoamyGuy