这是一个非常简单的问题,但我不知道该怎么做.我有一个listview适配器和一个xml行来显示每一行.我想在一行中显示3个textview.这是我的XML代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtElement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:textColor="#000000">
</TextView>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtElement2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:textColor="#000000">
</TextView>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/txtElement3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
android:textColor="#000000">
</TextView>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我希望文本显示如下:
txt1 txt2 txt3
这是我的适配器代码(但我想问题是在XML中):
TextView tv = (TextView) row.findViewById(R.id.txtElement);
tv.setText(currentElement.getTitle());
TextView tv2 = (TextView) row.findViewById(R.id.txtElement2);
tv2.setText(currentElement.getAuthor());
TextView tv3 = (TextView) row.findViewById(R.id.txtElement3);
tv3.setText(""+currentElement.getNumPost());
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我想要的是while循环运行并生成随机数量的int的随机列表.
import random
randAmount = random.randint(15,20)
randNumber = random.randint(2,5)
numbList = []
lookFor = 3
while len(numbList) < randAmount:
numbList.append(randNumber)
Run Code Online (Sandbox Code Playgroud)
我的输出:
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]
Run Code Online (Sandbox Code Playgroud)
为了randNumber重复不同的数字,我该怎么办?
注意:如果数字重复可以.