Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
235 views
Welcome To Ask or Share your Answers For Others

1 Answer

You need to add android:descendantFocusability="blocksDescendants" in your layout file of the custom listview or in each of the views add android:focusable="false". If any of the view in custom listview has focusable view then onitemclick does not work.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...