0
即時嘗試將OnClickListener添加到它由數組中的值生成的按鈕,但是m無法這樣做,這裏的任何建議?使用數組中的數據動態創建按鈕setOnClicklistener
long lprice = Long.parseLong(searchId.getText().toString());
List<String> buttonNameOne = dbc.getItemNameRbPrice(lprice);
List<String> buttonPriceOne = dbc.getPriceRbPrice(lprice);
List<String> buttonDateOne = dbc.getCurrentDateRbPrice(lprice);
for(int i = 0 ; i < buttonNameOne.size() ; i ++)
{
Button btn = new Button(this);
btn.setId(2000+i);
btn.setText(buttonNameOne.get(i) + i);
linearButton.addView(btn, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
Log.v("Value of element "+i, buttonNameOne.get(i));
Log.v("Value of element "+i, buttonPriceOne.get(i));
Log.v("Value of element "+i, buttonDateOne.get(i));
}
你添加一個按鈕,一個按鈕? 'linearButton.addView(btn ...)' – bclymer
我將我的佈局劃分爲2個LinearLayout ...並循環並在Linearlayout名稱中創建按鈕「linearButton」 – user2149618
試試這個http://stackoverflow.com/questions/9049843/編程-動態加載按鈕控制到視圖使用單聲道換機器人 –