android progressbar listview,Android ListView onItemClickListener being blocked by ProgressBar

问题

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:descendantFocusability="blocksDescendants" >

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

main_activity.xml:

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

android:id="@+id/main"

android:layout_width="match_parent"

android:layout_height="match_parent" >

android:id="@+id/drawer"

android:layout_width="240dp"

android:layout_height="match_parent"

android:layout_gravity="left"

android:background="#000"

android:choiceMode="singleChoice" />

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

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(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);

}

});

}

回答1:

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:

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

android:id="@+id/main"

android:layout_width="match_parent"

android:layout_height="match_parent" >

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

android:id="@+id/drawer"

android:layout_width="240dp"

android:layout_height="match_parent"

android:layout_gravity="left"

android:background="#000"

android:choiceMode="singleChoice" />

回答2:

There are multiple View inside your DrawerLayout.

The doc suggest you only have two!

To add a navigation drawer, declare your user interface with a

DrawerLayout object as the root view of your layout. Inside the

DrawerLayout, add one view that contains the main content for the

screen (your primary layout when the drawer is hidden) and another

view that contains the contents of the navigation drawer.

I would suggest to group the ListvView and the ProgressBar in one container

来源:https://stackoverflow.com/questions/18237218/android-listview-onitemclicklistener-being-blocked-by-progressbar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值