我在页面上包含一个动态微调器。单击微调器时,它将下拉选择图像和文本。问题是当我想选择下面的值之一时,比如“B 类”,它不能被点击。为什么?我的代码有问题吗?
真的需要别人的帮助。
谢谢
*类别.java***
private Spinner iconSpinner;
String[] iconArrays = {"Category A", "Category B"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_categorydetails);
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection(){
iconSpinner = (Spinner) findViewById(R.id.iconSpinner);
iconSpinner.setAdapter(new MyCustomAdapter(this, R.layout.icon_row, iconArrays));
iconSpinner.setOnItemSelectedListener(this);
}
public class MyCustomAdapter extends ArrayAdapter<String>{
public MyCustomAdapter(Context context, int textViewResourceId,
String[] objects) {
super(context, textViewResourceId, objects);
// TODO Auto-generated constructor stub
}
@Override
public View getDropDownView(int position, View convertView,
ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
return getCustomView(position, convertView, parent);
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
//return super.getView(position, convertView, parent);
//LayoutInflater inflater = (LayoutInflater) CategoryDetailsActivity.this.getApplicationContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
LayoutInflater inflater = getLayoutInflater();
View row=inflater.inflate(R.layout.icon_row, parent, false);
TextView label=(TextView)row.findViewById(R.id.iconLabel);
label.setText(iconArrays[position]);
ImageView icon=(ImageView)row.findViewById(R.id.icon);
if (iconArrays[position]=="Category A"){
icon.setImageResource(R.drawable.ic_catA);
}
else{
icon.setImageResource(R.drawable.ic_catB);
}
return row;
}
}
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int pos,
long arg3) {
// TODO Auto-generated method stub
Toast.makeText(arg0.getContext(),
"OnItemSelectedListener : " + arg0.getItemAtPosition(pos).toString(),
Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
* icon_row.xml***
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:orientation="horizontal">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/stringIcon"
android:layout_margin="10dip"/>
<TextView
android:id="@+id/iconLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:layout_margin="10dip"/>
</LinearLayout>