public class uploadActivity extends Activity implements OnClickListener {
protected void onCreate(Bundle savedInstanceState)
{
Spinner spinner = (Spinner) findViewById(R.id.spinner_list);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spinner_arrays, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
}
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Toast.makeText(parent.getContext(), "Selected entry in spinner is : " + parent.getItemAtPosition(pos).toString(), Toast.LENGTH_SHORT).show();
}
public void onNothingSelected(AdapterView<?> parent) {
}
}
我正在尝试将微调器添加到我的类活动中但是在我的项目中有4个按钮我需要实现OnClickListener并且我已经完成了它的功能所以我不能将onclicklistener更改为OnItemSelectedListener并且我正在尝试下面的方法但是因为我还没有实现OnItemSelectedListener。当我点击条目时不会调用像onItemSelected这样的方法,所以如何在dis case中实现
谢谢
答案 0 :(得分:2)
试试这个..
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View v,
int position, long id) {
Log.v("SpinnerSelected Item",
"" + spinner.getSelectedItem());
Log.v("Clicked position",""+position);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
Log.v("NothingSelected Item",
"" + spinner.getSelectedItem());
}
});
或者,您可以使用如下
public class uploadActivity extends Activity implements OnClickListener,OnItemSelectedListener{