所以,我想为Spinner分配OnClick事件,但是我遇到了以下错误。
有什么方法可以做到吗?谢谢!
java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
我需要在点击spinner时收集数据,然后稍后再使用它。 我知道以前做过,但是我丢失了代码。搜索答案,但没有找到可用的。 如果有帮助的话,我正在使用pagerview布局。 以下是我的代码:
public class DATA extends Fragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (container == null) {
return null;
}
ScrollView GPU_LAYOUT = (ScrollView)inflater.inflate(R.layout.gpu, container, false);
final TextView higher_than =(TextView) GPU_LAYOUT.findViewById(R.id.gpu_higher_than_value);
final Spinner min_max =(Spinner) GPU_LAYOUT.findViewById(R.id.min_max_spinner_gpulay);
min_max.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String TMP=min_max.getSelectedItem().toString();
higher_than.setText(TMP);
}
});
return GPU_LAYOUT;
}
有什么方法可以做到吗?谢谢!