選択したスピナー オプションを同じアクティビティの TextView に表示したい。スピナーをクリックすると複数のオプションがドロップされますが、選択しても何も起こりません。TextView は変更されません。
コード:
package com.kk.project;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
public class Addproject extends Activity implements OnItemSelectedListener {
int mPos;
String mSelection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_addproject);
Spinner spinner = (Spinner) findViewById(R.id.difficultyspinner); ArrayAdapter<CharSequence>
adapter = ArrayAdapter.createFromResource(this,R.array.difficultyarray, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_addproject, menu);
return true;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
// TODO Auto-generated method stub
Addproject.this.mPos = pos;
Addproject.this.mSelection = parent.getItemAtPosition(pos).toString();
TextView spinnerresult = (TextView)findViewById(R.id.spinnertxt);
spinnerresult.setText(Addproject.this.mSelection);
Spinner spinner = (Spinner)findViewById(R.id.spinnertxt);
spinner.setOnItemSelectedListener(this);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
//NOTHING
}
}