私は、プログラムによってJavaファイルを通じて作成されたボタンを使用しています。私は機能を表すボタンonclickリスナーを使用しています。そのボタンのクリックリスナー内にスピナーを追加することは可能ですか?私のコードはここに行く:私はこのコードを使用する場合ボタン内のAndroidスピナーonclicklistener
View.OnClickListener newtodobtn = new View.OnClickListener() {
public void onClick(View v) {
// it was the 1st button
setContentView(R.layout.main);
sp1 = (Spinner)findViewById(R.id.spinner1);
ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.priority, R.id.spinner1);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
sp1.setAdapter(adapter);
sp1.setAdapter(adapter);}
、私は、次の取得エラー:
The method createFromResource(Context, int, int) in the type ArrayAdapter is not applicable for the arguments (new View.OnClickListener(){}, int, int)
がすべてのヘルプは高く評価され、感謝事前に
エラーが発生しました: ArrayAdapter型のcreateFromResource(Context、int、int)メソッドは引数には適用されません(新しいView.OnClickListener(){}、int、int) –
そのため、 YourActivity.this 'に変更します。 'YourActivity'は、現在の' Activity.java'または現在の 'Context'を意味します。 –
こんにちは、私はこのエラーを次のコードで克服しました: スピナースピナー=(スピナー)findViewById(R.id.spinner1); \t ArrayAdapter adap = new ArrayAdapter(this、android.R.layout.simple_spinner_item、level); spinner.setAdapter(アダプタ); –