2017-06-30 9 views
0

グリッドビューアダプタにボタン配列を追加しようとしています。このプログラムを実行するのを手伝ってください。グリッドビューを使用してボタン配列をアダプタに追加する

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); 
+0

この問題は何ですか?あなたは実際に何が問題になっているのかを指定する必要があります。 – Clonkex

答えて

0

はあなたが各項目にしたいビューのタイプ、この場合はボタンを返すようにgetViewメソッドを()ArrayAdapterクラスを拡張し、オーバーライドする必要があります。型パラメータを持たない型を試してみることもできます。

https://developer.android.com/guide/topics/ui/declaring-layout.html#AdapterViews

+0

ありがとうございます。本当に有益なものになるための簡単な例を教えてください。 –

+0

ボタン[]ボタン= ... とgetView() 戻りボタン[i]; – amahfouz

関連する問題