Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java ProgressBar正在阻止Android ListView侦听器_Java_Android_Listview_Clicklistener_Focusable - Fatal编程技术网

Java ProgressBar正在阻止Android ListView侦听器

Java ProgressBar正在阻止Android ListView侦听器,java,android,listview,clicklistener,focusable,Java,Android,Listview,Clicklistener,Focusable,我让我的监听器在抽屉布局中为我的ListView工作,工作正常。但是我添加了一个ProgressBar,它显示在任何其他内容之前,然后设置为View.GONE。 但是,我无法再从列表视图中选择和项 list_item.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="h

我让我的监听器在抽屉布局中为我的ListView工作,工作正常。但是我添加了一个ProgressBar,它显示在任何其他内容之前,然后设置为View.GONE。 但是,我无法再从列表视图中选择和项

list_item.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants" >

<TextView
    android:id="@+id/label"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#000000"
    android:focusable="false"
    android:paddingBottom="25dp"
    android:textColor="#ffffff"
    android:textSize="20sp" >
</TextView>

</RelativeLayout>

main_activity.xml:

<android.support.v4.widget.DrawerLayout       xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
</FrameLayout>

<ListView
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="#000"
    android:choiceMode="singleChoice" />

<ProgressBar
    android:id="@+id/device_progress"
    style="?android:attr/progressBarStyleSmall"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:indeterminateDrawable="@drawable/progress"
    android:visibility="gone" />

</android.support.v4.widget.DrawerLayout>

Java代码:

    @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Log.d(TAG, "Executing onCreate().");
    setContentView(R.layout.activity_devices);
    progress = (ProgressBar) findViewById(R.id.device_progress);
    progress.setVisibility(View.VISIBLE);
    manager = MainScreenActivity.getDeviceManager();
    manager = MainScreenActivity.getDeviceManager();
    drawerInfo = manager.getDrawerInfo();
    mDrawerList = (ListView) findViewById(R.id.drawer);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    adapter = new ArrayAdapter<String>(this,
            R.layout.drawer_list_item, R.id.label, drawerInfo);
    mDrawerList.setAdapter(adapter);
    mDrawerLayout
            .setDrawerListener(new DrawerLayout.SimpleDrawerListener() {
                @Override
                public void onDrawerClosed(View drawerView) {
                    super.onDrawerClosed(drawerView);
                    Log.d(TAG, "onDrawerClosed() executed!");
                }

                @Override
                public void onDrawerOpened(View view) {
                    super.onDrawerOpened(view);
                    Log.d(TAG, "onDrawerOpened() executed!");
                    refreshDrawer();
                }
            });
    mDrawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                final int pos, long id) {
            Log.d(TAG, "CLICKED " + pos);
            selectDevice(pos);
        }
    });
}
@覆盖
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
d(标记“Executing onCreate()”);
setContentView(R.layout.activity\u设备);
进度=(进度条)findViewById(R.id.device\u进度);
progress.setVisibility(View.VISIBLE);
manager=MainScreenActivity.getDeviceManager();
manager=MainScreenActivity.getDeviceManager();
DroperInfo=manager.getDroperInfo();
mDrawerList=(ListView)findViewById(R.id.drawer);
mDrawerLayout=(抽屉布局)findViewById(R.id.抽屉布局);
适配器=新阵列适配器(此,
R.布局图、抽屉清单、R.id.标签、抽屉信息);
mDrawerList.setAdapter(适配器);
mDrawerLayout
.setDroperListener(新的DroperLayout.SimpleDrawerListener(){
@凌驾
图纸上的公共空白已关闭(视图抽屉视图){
super.onDrawerClosed(抽屉视图);
d(标记“onDrawerClosed()已执行!”);
}
@凌驾
已打开的公共空间(视图){
super.onDrawerOpened(视图);
d(标记“onDrawerOpened()已执行!”);
刷新抽屉();
}
});
setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
最终整数位置,长id){
Log.d(标记“点击”+pos);
选择设备(pos);
}
});
}

抽屉布局中有多个视图。 建议你只有两个

要添加导航抽屉,请使用 DroperLayout对象作为布局的根视图。内部 抽屉布局,添加一个包含抽屉主要内容的视图 屏幕(抽屉隐藏时的主布局)和另一个 包含导航抽屉内容的视图


我建议将ListvView和ProgressBar分组在一个容器中,找到解决方案,而不是在根抽屉布局中添加新元素,而是将其放在框架布局中主要内容应该放的地方。我犯了一个愚蠢的错误,但如果其他人也有同样的问题。这是:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<FrameLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ProgressBar
        android:id="@+id/device_progress"
        style="?android:attr/progressBarStyleLarge"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:indeterminateDrawable="@drawable/progress"
        android:visibility="gone" />
</FrameLayout>

<ListView
    android:id="@+id/drawer"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:background="#000"
    android:choiceMode="singleChoice" />

</android.support.v4.widget.DrawerLayout>


我确信添加xml不会破坏任何东西。。您没有修改Java代码中的某些内容吗?@wazau_Be我添加了我的Java代码,当我注释/删除XML和Java代码时,效果很好。所以这肯定是因为progressbar,在progressbar显示之前您是否禁用/隐藏listview?隐藏进度条后是否启用/显示listview?在答案中添加一些代码。如何将它们添加到一个容器中?您听说过LinearLayout吗?把它们放在一条垂直的直线上。我试过这个,但它弄坏了,我再也拔不出我的抽屉了。改变代码:不要问我明显做了什么,你可以看到代码。你为什么不告诉我该怎么做?是的,我做到了。您说过将进度条和列表视图放在线性布局中。如果我做得不对,请告诉我怎么做。谢谢。对不起,我不是你在一台有开发IDE的电脑前的仆人。我不能给你这样的代码。。我所说的会起作用的。如果你不想感谢,尝试一点或努力,我浪费了我的时间帮助你,我感到很恼火