【发布时间】:2018-03-28 11:51:08
【问题描述】:
What I want it to look like
我有两个 arraylists,我在我的 res 文件夹中创建了一个自定义布局,两个 TextViews 并排。我希望能够用两个arraylists 填充这个customlayout,以便第一个列表中的第一个项目将显示在第二个列表中的第一个项目旁边。任何帮助将不胜感激。
带有 Listview 的两个 Arraylist:
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
String name = ds.getKey();
allStudentsList.add(name);
attendancePercentage.add("74%");
}
final ListView listView = findViewById(R.id.studentList);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getApplicationContext(), R.layout.percentage_layout, R.id.statsResult, allStudentsList);
listView.setAdapter(adapter);
自定义布局的 XML 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/classList"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="3"
android:text="TextView" />
<TextView
android:id="@+id/statsResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:layout_weight="3"
android:text="TextView" />
</LinearLayout>
【问题讨论】:
-
显示一些代码。
-
数组的行数是否相同?行的大小是否相同?试着画出你想要实现的线框。
-
是的,它们的行数相同,因此第一个数组列表将是一个类列表。第二个列表将是该特定学生的出勤记录。在上面的代码中,我刚刚硬编码每个学生旁边都有 74%
-
添加了我想要的样子
-
请使用自定义适配器。
标签: android listview arraylist adapter