我有 listView 有行每行应该有三个按钮
但我希望每个按钮都有唯一的文本,因为字符串列表有。
我已经尝试过该代码,但它给了我以下结果
1 1 1
2 2 2
3 3 3
但我想要这样:
1 2 3
4 5 6
7 8 9
我的类代码:
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView == null) {
LayoutInflater inflator = context.getLayoutInflater();
view = inflator.inflate(R.layout.rep2, null);
ViewHolder viewHolder = new ViewHolder();
viewHolder.Button1 = (Button) view.findViewById(R.id.Button01);
viewHolder.Button2 = (Button) view.findViewById(R.id.Button02);
viewHolder.Button3 = (Button) view.findViewById(R.id.Button03);
// viewHolder.row = (TableRow) view.findViewById(R.id.TableRow06);
view.setTag(viewHolder);
viewHolder.row.setTag(ClassList.get(position));
viewHolder.Button1.setTag(ClassList.get(position));
viewHolder.Button2.setTag(ClassList.get(position));
viewHolder.Button3.setTag(ClassList.get(position));
} else {
view = convertView;
((ViewHolder) view.getTag()).Button1
.setTag(ClassList.get(position));
((ViewHolder) view.getTag()).Button2
.setTag(ClassList.get(position));
((ViewHolder) view.getTag()).Button3
.setTag(ClassList.get(position));
((ViewHolder) view.getTag()).row.setTag(ClassList.get(position));
}
布局xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/Button01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/classes" />
<Button
android:id="@+id/Button02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/classes" />
<Button
android:id="@+id/Button03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="25dp"
android:background="@drawable/classes" />
</LinearLayout>