当listrow中填充了微调器时,android onListItemClick无法正常工作

我正在尝试填充列表视图,其中行包含复选框,四个textviews和两个微调器.每行上的微调器中的值需要不同,因为它们与该行上的实际项直接相关.只是为了使它变得更复杂一点,除非选中复选框,否则微调器和它们旁边的两个文本字段是不可见的(setVisibility(View.GONE)).我只想要列表项可点击(而不是复选框),并且一旦显示,微调器就需要可点击.

我的所有代码都正常工作,除了当填充微调器时,我失去了单击该行上的列表项的能力.我仍然可以从该行上的微调器中选择值,但触摸该行上的任何其他位置都没有任何作用.有些行不会将数据返回到微调器,并且它们继续正常运行,因此我认为它与连接到微调器的适配器有关.

此外,我知道我将不得不考虑列表视图回收,但我还没有那么远.

我希望有人能在我完全疯了之前指出这里有什么问题.

这是listview xml

<ListView android:id="@+id/android:list"
      android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

<TextView android:id="@+id/android:empty"
          android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/empty"/>
</LinearLayout>

这是行xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" 
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">

        <CheckBox android:id="@+id/pl_selected"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:focusableInTouchMode="false"
            android:clickable="false"
            android:focusable="false"
            android:layout_weight="1"/>

        <TextView android:id="@+id/name"
                android:layout_width="fill_parent"
            android:layout_height="wrap_content"
        android:layout_weight="1"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:focusable="false"/>

    <TextView android:id="@+id/name2" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:focusableInTouchMode="false"
        android:clickable="false"
        android:focusable="false"/>

</LinearLayout>

<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/pl_tv1" 
            android:text="@string/pl_tv1" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:focusableInTouchMode="false"
            android:clickable="false"
            android:focusable="false"
            android:visibility="gone"/>

    <Spinner android:id="@+id/pl_spin1"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:visibility="gone"
            android:focusableInTouchMode="false"
            android:focusable="false"/>
</LinearLayout>
<LinearLayout android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/pl_tv2"
            android:text="@string/pl_tv2" 
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:focusableInTouchMode="false"
            android:clickable="false"
            android:focusable="false"
            android:visibility="gone"/>

    <Spinner android:id="@+id/pl_spin2"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:visibility="gone"
            android:focusableInTouchMode="false"
            android:focusable="false"/>
</LinearLayout>
</LinearLayout>

以下是大多数不相关的东西的活动:

import android.widget.SimpleCursorAdapter;
import mdhsoft.band.Tab.DbAdapter;
import mdhsoft.band.Tab.R;
import android.os.Bundle;
import android.app.ListActivity;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;

public class PLActivity extends ListActivity {
    private static final int DONE_ID = Menu.FirsT;
    private DbAdapter mDbHelper;
private int mPlId;
private CheckBox mCheckBox;
private Spinner mSpin1;
private Spinner mSpin2;
private TextView mtv1;
private TextView mtv2;
private int mItemId; 
private SimpleCursorAdapter mAllItems;
private Cursor mSCursor;
private Cursor mcurSpin1;
private Cursor mcurSpin2;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pl_list);

        Bundle extras = getIntent().getExtras();
        mPlId = extras.getInt(DbAdapter.KEY_PLID);
        mDbHelper = new DbAdapter(this);
        mDbHelper.open();

        fillData();
        registerForContextMenu(getListView());
    }

private void fillData() {
    mSCursor = mDbHelper.fetchAllPl(mPlId);
    startManagingCursor(mSCursor);
    String[] from = new String[]
        {"pl_selected",DbAdapter.KEY_SNAME,DbAdapter.KEY_SNAME2};
    int[] to = new int[]{R.id.pl_selected,R.id.name,R.id.name2};
    mAllItems = new SimpleCursorAdapter(this,R.layout.pl_row,mSCursor,from,to);
    mAllItems.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        public boolean setViewValue(View view,Cursor cursor,int columnIndex) {
            if(columnIndex == 3) {
                    CheckBox cb = (CheckBox) view; 
                    cb.setChecked(cursor.getInt(3) > 0);
                    ViewGroup row = (ViewGroup)view.getParent();
                    if (cursor.getInt(3) > 0) {
                        mcurSpin1 = (Spinner) row.findViewById(R.id.pl_spin1);
                        mcurSpin2 = (Spinner) row.findViewById(R.id.pl_spin2);
                        mtv1 = (TextView) row.findViewById(R.id.pl_tv1);
                        mtv2 = (TextView) row.findViewById(R.id.pl_tv2);
                        mcurSpin1.setVisibility(View.VISIBLE);
                        mtv1.setVisibility(View.VISIBLE);
                        mcurSpin2.setVisibility(View.VISIBLE);
                        mtv2.setVisibility(View.VISIBLE);
                        PopulateSpinner1();
                        PopulateSpinner2(); 
                    }
                    return true;
            }
            return false;
        }
    });
    setlistadapter(mAllItems);
}

private void PopulateSpinner1(){
    mcurSpin1 = mDbHelper.fetchSByItemId(mItemId);
    startManagingCursor(mcurSpin1);
    String[] from = new String[]{DbAdapter.KEY_SNAME};
    int[] to = new int[]{android.R.id.text1};
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,mcurSpin1,to );
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item);
    mSpin1.setAdapter(adapter);

}

private void PopulateSpinner2(){
    mcurSpin2 = mDbHelper.fetchMByItemId(mItemId);
    startManagingCursor(mcurSpin2);
    String[] from = new String[]{DbAdapter.KEY_MNAME};
    int[] to = new int[]{android.R.id.text1};
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,mcurSpin2,to );
    adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item);
    mSpin2.setAdapter(adapter);
}

@Override
protected void onListItemClick(ListView l,View v,int position,long id) {
    super.onListItemClick(l,v,position,id);
    ViewGroup row = (ViewGroup)v;
    mSCursor.movetoPosition(position);
    mItemId = mSCursor.getInt(mSCursor.getColumnIndex(DbAdapter.KEY_SID));
    mCheckBox = (CheckBox) row.findViewById(R.id.pl_selected);
    mcurSpin1 = (Spinner) row.findViewById(R.id.pl_spin1);
mcurSpin2 = (Spinner) row.findViewById(R.id.pl_spin1);
mtv1 = (TextView) row.findViewById(R.id.pl_tv1);
mtv2 = (TextView) row.findViewById(R.id.pl_tv2);
    if (mCheckBox.isChecked()) {
        mCheckBox.setChecked(false);
        mcurSpin1.setVisibility(View.GONE);
        mtv1.setVisibility(View.GONE);
        mcurSpin2.setVisibility(View.GONE);
        mtv2.setVisibility(View.GONE);
}
    else {
        mCheckBox.setChecked(true);
        mcurSpin1.setVisibility(View.VISIBLE);
        mtv1.setVisibility(View.VISIBLE);
        mcurSpin2.setVisibility(View.VISIBLE);
        PopulateSpinner1();
        PopulateSpinner2(); 

    }
  }

}

在此先感谢您提供任何帮助.

解决方法

您可以尝试将android:descendantFocussability = blocksDescendants添加到最顶部的线性布局.这可能会有所帮助.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


这篇“android轻量级无侵入式管理数据库自动升级组件怎么实现”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定...
今天小编给大家分享一下Android实现自定义圆形进度条的常用方法有哪些的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文...
这篇文章主要讲解了“Android如何解决字符对齐问题”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Android...
这篇文章主要介绍“Android岛屿数量算法怎么使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Android岛屿数量算...
本篇内容主要讲解“Android如何开发MQTT协议的模型及通信”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Andro...
本文小编为大家详细介绍“Android数据压缩的方法是什么”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android数据压缩的方法是什么”文章能帮助大家解决疑惑...
这篇“Android怎么使用Intent传大数据”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅...
本文小编为大家详细介绍“Android事件冲突怎么解决悬浮窗拖拽问题”,内容详细,步骤清晰,细节处理妥当,希望这篇“Android事件冲突怎么解决悬浮窗拖拽问题”文...
这篇文章主要介绍了Android拼接如何实现动态对象的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android拼接如何实现动态对象文...
今天小编给大家分享一下Android全面屏适配怎么实现的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下...
本篇内容介绍了“Android怎么开发Input系统触摸事件分发”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何...
今天小编给大家分享一下AndroidRoom怎么使用的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下...
本文小编为大家详细介绍“AndroidRoom使用方法有哪些”,内容详细,步骤清晰,细节处理妥当,希望这篇“AndroidRoom使用方法有哪些”文章能帮助大家...
这篇文章主要介绍“Android中的OpenGL怎么配置使用”的相关知识,小编通过实际案例向大家展示操作过程,操作方法简单快捷,实用性强,希望这篇“Android中的Open...
这篇文章主要介绍了Android如何自定义自动识别涂鸦工具类的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇Android如何自定义自动...
今天小编给大家分享一下Android如何自定义有限制区域的图例角度自识别涂鸦工具类的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以...
今天小编给大家分享一下ReactNative错误采集原理在Android中如何实现的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章...
这篇文章主要讲解了“Android崩溃日志收集和保存代码分析”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“A...
这篇“Android面向单Activity开发实例分析”文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大...
本篇内容介绍了“Android应用启动白屏处理的方法是什么”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何...