这是我对 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/