I am creating a custom ListView in which I have two identical rows and one is different with a Spinner in it. The problem is that the row with Spinner is not clickable. I can only click on Spinner. Here is my adapter:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
int theType = getItemViewType(position);
if (convertView == null) {
holder = new ViewHolder();
if (theType == 0) {
convertView = inflat.inflate(R.layout.row_item0, parent, false);
holder.textView = (TextView) convertView
.findViewById(R.id.text);
holder.sp = (Spinner) convertView.findViewById(R.id.sp);
} else if (theType == 1) {
convertView = inflat.inflate(R.layout.row_item1, null);
holder.textView = (TextView) convertView
.findViewById(R.id.text);
}
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
String it = items.get(position);
if (it != null) {
if (theType == 0) {
holder.textView.setText(it);
holder.sp.setAdapter(new CategorySpinnerAdapter(
getApplicationContext(),
R.layout.item_spinner_category, Data.lose_weight_type));
holder.sp
.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
Data.user
.setLose_weight_type(Data.lose_weight_type
.get(position));
Data.user.setGoal(Data.goals.get(0));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
} else if (theType == 1) {
holder.textView.setText(it);
}
}
return convertView;
}
See Question&Answers more detail:os