Android的ListView控件onItemClickListener被拦截的进度 [英] Android ListView onItemClickListener being blocked by ProgressBar

查看:149
本文介绍了Android的ListView控件onItemClickListener被拦截的进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的onItemClickListener我的我的DrawerLayout做工精细的ListView里面工作。但是,我补充说,在别的然后将它设置为View.GONE之前会显示进度条。
但是,我不能选择从我的列表项查看了。

list_item.xml

 <?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:descendantFocusability =blocksDescendants><的TextView
    机器人:ID =@ + /标记
    机器人:layout_width =match_parent
    机器人:layout_height =WRAP_CONTENT
    机器人:背景=#000000
    机器人:可聚焦=假
    机器人:paddingBottom会=25dp
    机器人:文字颜色=#FFFFFF
    机器人:TEXTSIZE =20SP>
< / TextView的>< / RelativeLayout的>

main_activity.xml:

 < android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。><的FrameLayout
    机器人:ID =@ + ID /主
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>
< /&的FrameLayout GT;< ListView控件
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =240dp
    机器人:layout_height =match_parent
    机器人:layout_gravity =左
    机器人:背景=#000
    机器人:choiceMode =singleChoice/><进度
    机器人:ID =@ + ID / device_progress
    风格=机器人:ATTR / progressBarStyleSmall
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:layout_centerHorizo​​ntal =真
    机器人:layout_centerVertical =真
    机器人:indeterminateDrawable =@绘制/进步
    机器人:知名度=水涨船高/>< /android.support.v4.widget.DrawerLayout>

Java的code:

  @覆盖
保护无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    Log.d(TAG,执行的onCreate());
    的setContentView(R.layout.activity_devices);
    进度=(进度)findViewById(R.id.device_progress);
    progress.setVisibility(View.VISIBLE);
    经理= MainScreenActivity.getDeviceManager();
    经理= MainScreenActivity.getDeviceManager();
    drawerInfo = manager.getDrawerInfo();
    mDrawerList =(ListView控件)findViewById(R.id.drawer);
    mDrawerLayout =(DrawerLayout)findViewById(R.id.drawer_layout);
    适配器=新ArrayAdapter<串GT;(这一点,
            R.layout.drawer_list_item,R.id.label,drawerInfo);
    mDrawerList.setAdapter(适配器);
    mDrawerLayout
            .setDrawerListener(新DrawerLayout.SimpleDrawerListener(){
                @覆盖
                公共无效onDrawerClosed(查看drawerView){
                    super.onDrawerClosed(drawerView);
                    Log.d(TAGonDrawerClosed()执行!);
                }                @覆盖
                公共无效onDrawerOpened(查看视图){
                    super.onDrawerOpened(视图);
                    Log.d(TAGonDrawerOpened()执行!);
                    refreshDrawer();
                }
            });
    mDrawerList.setOnItemClickListener(新OnItemClickListener(){        @覆盖
        公共无效onItemClick(适配器视图<>母公司,观景,
                最终诠释POS,长I​​D){
            Log.d(TAG,点击+ POS)
            selectDevice(POS)
        }
    });
}


解决方案

找到了解决办法,而不是添加一个新的元素根DrawerLayout里面,把它放在那里的FrameLayout你的主要内容应该去里面。这是一个愚蠢的错误由我,但如果其他人是否有同样的问题。在这里,它是:

 < android.support.v4.widget.DrawerLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:工具=htt​​p://schemas.android.com/tool​​s
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent
工具:上下文=MainActivity。><的FrameLayout
    机器人:ID =@ + ID /主
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent>    <进度
        机器人:ID =@ + ID / device_progress
        风格=机器人:ATTR / progressBarStyleLarge
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =中心
        机器人:indeterminateDrawable =@绘制/进步
        机器人:知名度=水涨船高/>
< /&的FrameLayout GT;< ListView控件
    机器人:ID =@ + ID /抽屉
    机器人:layout_width =240dp
    机器人:layout_height =match_parent
    机器人:layout_gravity =左
    机器人:背景=#000
    机器人:choiceMode =singleChoice/>< /android.support.v4.widget.DrawerLayout>

I had my onItemClickListener working for my ListView inside of my DrawerLayout working fine. But I added a ProgressBar that is displayed before anything else then it is set to View.GONE. However, I can't select and items from my list view any more.

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 Code:

    @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);
        }
    });
}

解决方案

Found the solution, instead of adding a new element inside of the Root DrawerLayout, put it inside of the FrameLayout where your main content should go. This was a dumb mistake by me, but if anyone else is having the same problem. Here it is:

<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>

这篇关于Android的ListView控件onItemClickListener被拦截的进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆