android - ListView 改变行

标签 android listview

这是我对 ListView 每一行的布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llRow"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >
<LinearLayout
        android:id="@+id/llClosed"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

Stuff Inside

</LinearLayout>

<LinearLayout
        android:id="@+id/llOpen"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

Stuff Inside

</LinearLayout>
</LinearLayout>

我的想法是,当我单击一个 ListView 项目时,它会将 llClosed 设置为 Gone 并将 llOpen 设置为Visible 以便稍后使用一些动画创建扩展外观。

protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
                View open = v.findViewById(R.id.llOpen);
                View close = v.findViewById(R.id.llClosed);
                close.setVisibility(View.GONE);
        open.setVisibility(View.VISIBLE);
}

问题是,当我单击第一行时,它不仅会更改第一行,还会更改下 2 或 3 行的另一行。什么可能导致这种情况?

已解决:如果我在列表适配器中执行 llOpen.setVisibility(View.GONE),它将解决我的问题。

最佳答案

好吧,一个问题是你有两个具有相同 ID 的线性布局 android:id="@+id/llClosed"

布局中所有具有 ID 的元素都应该具有唯一的 ID。试试 android:id="@+id/llClosed1"android:id="@+id/llClosed2"

很抱歉,我无法真正说明您要完成什么,但看起来您可能想尝试 expandablelistview 类。 checkout :

http://techdroid.kbeanie.com/2010/09/expandablelistview-on-android.html

http://about-android.blogspot.com/2010/04/steps-to-implement-expandablelistview.html

关于android - ListView 改变行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9343609/

相关文章:

asp.net - 是否可以在 ASP.NET ListView 控件中进行自定义分组?

android - SwipeRefreshLayout 中的 ListView - 当自定义适配器只有一行要显示时不显示任何内容

JQuery Mobile ListView 缩略图对齐

.NET ListView,最大字符数还是最大列宽?可以覆盖/扩展吗?

android - 截取屏幕截图时更改小部件内容

Android NDK/JNI UnsatisfiedLinkError With .So library

android - 文本转语音未按预期工作

android - Intent 与 ACTION_VIEW 和 uri 指向 EXTRA_STREAM 中的 ParcelFileDescriptor

android - Logcat 错误 : "addView(View, LayoutParams) is not supported in AdapterView" in a ListView

android - 编译phonegap应用问题