holder.spinner_teacher_name=(Spinner) rowView.findViewById(R.id.spinner_teacher_name);
holder.spinner_teacher_name=(Spinner) rowView.findViewById(R.id.spinner_teacher_name);
arrayAdapter=new ArrayAdapter<String>(rowView.getContext(), android.R.layout.simple_spinner_item,teacher_name);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spinner_teacher_name.setAdapter(arrayAdapter);
holder.spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(rowView.getContext(), "You Clicked "+class_room[position], Toast.LENGTH_SHORT).show();
}
});
答案 0 :(得分:0)
您应该使用选定的侦听器,而不是单击侦听器
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
{
String selected_item = parent.getItemAtPosition(pos).toString();
Log.d("TAG", "_log : item_selected : " + selected_item);
}
public void onNothingSelected(AdapterView<?> parent)
{
}
});
答案 1 :(得分:0)
当用户selects
来自drop-down
的项目时,Spinner
对象会收到on-item-selected
个事件。
要为selection
定义spinner
事件处理程序,请实现AdapterView.OnItemSelectedListener
接口和相应的onItemSelected()
回调方法。
请参阅documentation。
使用:强>
holder.spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(rowView.getContext(), "You Clicked " + class_room[position], Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
代替:
holder.spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(rowView.getContext(), "You Clicked "+class_room[position], Toast.LENGTH_SHORT).show();
}
});