我想在列表项目单击时调用微调框,我可以在列表项目单击时成功“烤面包”,现在当我尝试调用“微调”,它给我以下错误:类型AdapterView <SpinnerAdapter>类型的方法setOnItemSelectedListener不适用于参数
"The method setOnItemSelectedListener(AdapterView.OnItemSelectedListener) in the type AdapterView is not applicable for the arguments (new View.OnClickListener(){})"
我该如何克服它?下面是我的代码:
注:这是我的适配器类,而不是活动类
if(oi.getOptionName().contains("Other")){
v.setBackgroundColor(Color.parseColor("#b2b2b2"));
option_image.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(mContext, "Hello", Toast.LENGTH_LONG).show();
//notifyDataSetChanged(); //added
v = vi.inflate(R.layout.spinner, null);
spinnerOsversions = (Spinner) v.findViewById(R.id.osversions);
// Spinner click listener
spinnerOsversions.setOnItemSelectedListener(UserSurveyAdapter.this);
// Spinner Drop down elements
List<String> categories = new ArrayList<String>();
categories.add("Automobile");
categories.add("Business Services");
categories.add("Computers");
categories.add("Education");
categories.add("Personal");
categories.add("Travel");
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, categories);
// Drop down layout style - list view with radio button
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spinnerOsversions.setAdapter(dataAdapter);
}
});
}
R.layout.spinner XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Spinner
android:id="@+id/osversions"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" />
</RelativeLayout>
你也可以发布你的布局。我看到你有这个 'spinnerOsversions =(微调)v.findViewById(R.id.osversions);'onClick是微调的按钮的孩子? – Raghunandan
感谢@Raghunandan对它进行调查。我已经更新了我的代码,现在它没有错误,但是在点击项目时,我看到吐司来了,但是微调并没有调用。 – user45678
微调器属于哪个布局。你膨胀一个布局,但它附着在哪里。此外,微调选择监听器应该移动到onClick – Raghunandan