所以我希望能够在ArrayList
上放置TextView
的多行数据。
这是我要显示的代码:
public void displayScores(){
ArrayList<LinkedHashMap<String, String>> list = db.getAllUsersWithScores();
for(LinkedHashMap<String, String> map : list){
//I had to check if my arraylist had any data first
Log.d("displayScores", "name: " + map.get("username"));
Log.d("displayScores", "score: " + map.get("score"));
}
}
这是我的XML文件。这是我打算显示上述方法的数据的地方:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container_scores"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="top">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="@+id/txtName"
android:textSize="24sp"
android:layout_below="@+id/txtScore"
android:layout_centerHorizontal="true"
tools:ignore="HardcodedText,PrivateResource"
android:gravity="center"
android:layout_weight="1"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:id="@+id/txtScore"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:layout_weight="1"
android:textSize="24sp" />
</LinearLayout>
</ScrollView>
如果我遗漏了任何相关的代码,请告诉我。
答案 0 :(得分:0)
只需在文本视图上调用setText()方法,如下所示:
TextView tvName = (TextView)findViewById(R.id.txtName);
TextView tvScore = (TextView)findViewById(R.id.txtScore);
tvName.setText("name: " + map.get("username"));
tvScore.setText("score: " + map.get("score"));