【发布时间】:2017-01-18 20:30:13
【问题描述】:
我正在使用列表视图,并且我在 raw.xml 中有 2 个不同的布局,我试图在我的自定义列表视图适配器类中通过它们的可见性(GONE、VISIBLE)来控制它们。我想更改特定项目的布局 onClick。但是当我点击listview项目时,即使我不点击它,也只有最后一个项目的布局效果。这是我的代码。提前致谢。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/advertisement_expandable"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
.
.
.
</LinearLayout>
<RelativeLayout
android:layout_margin="10dp"
android:id="@+id/layout2"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">
.
.
.
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
在我正在使用的适配器上;
RawView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(currentAdvertisement.isExpanded){
layout1.setVisibility(View.VISIBLE);
layout2.setVisibility(View.GONE);
currentAdvertisement.isExpanded=false;
}else{
layout1.setVisibility(View.GONE);
layout2.setVisibility(View.VISIBLE);
currentAdvertisement.isExpanded=true;
}
}
});
【问题讨论】:
标签: android android-layout listview listviewitem