【发布时间】:2018-10-06 10:36:58
【问题描述】:
我正在尝试按照这个很棒的教程(https://www.youtube.com/watch?v=c4XagtQlqS0)制作Expandable ListView。我遇到的问题是当我想“添加”第二个可扩展文本时。我得到的错误是“重复的 id @+id/expandable_text 最初定义在这里”和“重复的 id @+id/expand_collapse,已经在此布局的前面定义”。这是一个逻辑错误,但在教程中没有显示所以我的代码有问题吗?
你可以在下面找到我的代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context=".Body1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.ms.square.android.expandabletextview.ExpandableTextView
android:id="@+id/expandable_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxCollapsedLines="1"
app:animDuration="200"
>
<TextView
android:id="@+id/expandable_text"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="16dp"
android:textColor="#666"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/expand_collapse"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.ms.square.android.expandabletextview.ExpandableTextView>
<com.ms.square.android.expandabletextview.ExpandableTextView
android:id="@+id/expandable_text_view2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:maxCollapsedLines="1"
app:animDuration="200"
>
<TextView
android:id="@+id/expandable_text"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="16dp"
android:textColor="#666"
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageButton
android:id="@+id/expand_collapse"
android:layout_gravity="right|bottom"
android:background="@android:color/transparent"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</com.ms.square.android.expandabletextview.ExpandableTextView>
</ScrollView>
</LinearLayout>
还有java文件:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import com.ms.square.android.expandabletextview.ExpandableTextView;
public class Body1 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_body1);
ExpandableTextView expandableTextView1 = (ExpandableTextView) findViewById(R.id.expandable_text_view);
expandableTextView1.setText(getString(R.string.text1));
ExpandableTextView expandableTextView2 = (ExpandableTextView) findViewById(R.id.expandable_text_view);
expandableTextView2.setText(getString(R.string.text2));
}
}
提前感谢您的帮助!
【问题讨论】:
标签: android expandablelistview