I am trying to add Buttons array in grid view adapter. Please help me to run this programme.
for (int index = 0; index < Item.length; index++) {
myButton[index] = new Button(this); //initialize the button here
myButton[index].setText(Item[index]);
myButton[index].setWidth(120);
myButton[index].setHeight(120);
myButton[index].setId(index);
//myButton[index].setTag(index);
// scrViewButLay.addView(myButton[index]);
myButton[index].setOnClickListener(getOnClickDoSomething(myButton[index]));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, myButton);
You need to extend the ArrayAdapter class and override getView() to return the type of view you want for each item, a button in this case. You can then try or use the type with no type parameter.
https://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.