SetText逐行

时间:2016-01-12 14:27:28

标签: android android-layout android-activity android-dialog

我试图将TextView设置为读取来自算法的数字结果。我想逐行排序。这些数字现在彼此相邻。我怎样才能逐行制作它们? 我创建了一个新的自定义对话框,其中TextView名为Peak_num,但我无法进一步对其进行排序。我希望有一个人可以帮助我。

 List<Integer> List_Of_Peaks = findPeaks(String_TO_List);
 dialog.setTitle("my Dialog");
 dialog.setContentView(R.layout.customdialog);
 dialog.show();
 Log.i(TAG, "Peaks" + List_Of_Peaks);   
 Peaks_num = (TextView) dialog.findViewById(R.id.Peak_Num);
 Peaks_num.setText(String.valueOf(List_Of_Peaks));


 <?xml version="1.0" encoding="utf-8"?>
 <RelativeLayout 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/Peak_Num"
        android:layout_width="159dp"
        android:layout_height="wrap_content"
         android:background="@drawable/back"
        android:text="Peaks"
        android:textColor="#040307"
        android:layout_weight="1" />

This is how the dialog looks like, and I wanted them to be in row by row

1 个答案:

答案 0 :(得分:1)

 List<Integer> List_Of_Peaks = findPeaks(String_TO_List);
 dialog.setTitle("my Dialog");
 dialog.setContentView(R.layout.customdialog);
 dialog.show();
 Log.i(TAG, "Peaks" + List_Of_Peaks);   
 Peaks_num = (TextView) dialog.findViewById(R.id.Peak_Num);
 String text="";
 for(Integer integer:List_Of_Peaks)
 {
      text+=integer+"\n"; // split
 }
 Peaks_num.setText(text);