Android ListView onItemClickListener being blocked by ProgressBar
Asked Answered
A

2

0

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);
        }
    });
}
Aletaaletha answered 14/8, 2013 at 16:26 Comment(3)
I am sure that adding the xml didn't break anything.. Haven't you modified something in your Java code?Poolroom
@Poolroom I added my Java code, when I comment out / delete the XML and Java code it works fine. So it's definitely because of the ProgressBarAletaaletha
Do you disable/hide listview before progressbar was shown? And do you enable/show listview after after progress bar was hidden? Add some code to your answer.Brookes
A
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:

<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>
Aletaaletha answered 14/8, 2013 at 18:13 Comment(0)
P
0

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

Poolroom answered 14/8, 2013 at 16:35 Comment(11)
How do I go about adding them in one container?Aletaaletha
Have you heard about LinearLayout? Put both of them in one vertical LinearLayoutPoolroom
I tried this and it breaks it, I cannot pull out my drawer any more. Changed code: pastebin.com/GCdYL4SBAletaaletha
Instead of asking what I obviously did, as you can see the code. Why don't you tell me what to do? Which, I did. You said put the progress bar and ListView in a linear layout. If I did in incorrectly, tell me how please. Thanks.Aletaaletha
Sorry, I am not you servant in front of a computer with developement IDE. I cannot give you code like this.. What I said WILL work. If you don't want to thank, try a little bit or to make effort, I wasted my time helping, and I feel annoyedPoolroom
I am not saying you're my servant, but I apparently did something wrong, and instead of saying something useful you merely made a remark of apparently how obvious of a mistake I did ( Or atleast that was the tone I got) Sorry if that wasn't the tone. Did you look at the pastebin I posted. You can see I made a LinearLayout with vertical orientation.Aletaaletha
As I cannot test YOUR code, I just tell you how to make it work: use 2 childrean in DrawerLayout. One with your main layout and one with your Drawer. Apparently, it doesn't work with the second layout you tried, but well with a simple ListView.. Why? I have no idea as I cannot test. Try with something simple, like a LinearLayout with a red background. If worked, add the list inside, if worked again, add progressbar. WHen it doesn't work, tell us at which step it stopped workingPoolroom
Alright, so I changed the gravity of the LinearLayout to left and it works and all, however, it makes it look very strange when I pull it out, I might be able to fix that my self. But now I get a ClassCastException when I do mDrawerLayout.closeDrawer(mDrawerList); Says it cannot cast LinearLayout, however, I am not giving it a linear layout.Aletaaletha
You gave you listview a @id/drawer in your example, I am pretty sure you duplicated it to your LinearLayoutPoolroom
let us continue this discussion in chatPoolroom
I am in the chat room.Aletaaletha

© 2022 - 2024 — McMap. All rights reserved.