gpt4 book ai didi

java - Android ListView onItemClickListener 被 ProgressBar 阻止

转载 作者:行者123 更新时间:2023-12-01 14:14:32 25 4
gpt4 key购买 nike

我的 onItemClickListener 为我的 DrawerLayout 内的 ListView 工作正常。但我添加了一个在其他任何内容之前显示的 ProgressBar,然后将其设置为 View.GONE。但是,我无法再从 ListView 中选择项目。

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

最佳答案

找到了解决方案,不要在 Root DrawerLayout 中添加新元素,而是将其放在主要内容所在的 FrameLayout 中。这是我犯的一个愚蠢的错误,但如果其他人也遇到同样的问题。这是:

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

关于java - Android ListView onItemClickListener 被 ProgressBar 阻止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18237218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com