android - Android中使用TextView、TextView、RadioGroup自定义ListView

标签 android listview android-arrayadapter custom-adapter

我正在开发一个应用程序 ListView用于创建学生标记列表。

在此应用程序中,列表中有 10 名学生。针对这些学生进行的考试提供了四个等级。一名学生只能适应四个年级中的一个年级。

教师将在 ListView 中为学生分配成绩.

我的xml文件Studentlist.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="vertical" >
<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
</ListView>
</LinearLayout>

我的row.xml文件如下:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="500dp"
android:layout_height="fill_parent"
android:padding="10dp" >

<TableRow>

    <TextView
        android:id="@+id/SNo"
        style="@style/text"
        android:layout_width="40dp"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/StudNo"
        style="@style/text"
        android:layout_width="80dp"
        android:layout_height="wrap_content" />

    <TextView
        android:id="@+id/StudName"
        style="@style/text"
        android:layout_width="180dp"
        android:layout_height="wrap_content" />

    <RadioGroup
        android:id="@+id/radioGroup1"
        android:layout_width="160dp"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <RadioButton
            android:id="@+id/radio0"
            android:layout_width="40dp"
            android:layout_height="wrap_content"
            android:checked="true" />

        <RadioButton
            android:id="@+id/radio1"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/radio2"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />

        <RadioButton
            android:id="@+id/radio3"
            android:layout_width="40dp"
            android:layout_height="wrap_content" />
    </RadioGroup>
</TableRow>

现在我正在尝试以下形式的输出:

1 0001 AAAA <RadioButton1> <RadioButton2> <RadioButton3> <RadioButton4>
2 0002 BBBB <RadioButton1> <RadioButton2> <RadioButton3> <RadioButton4>

如何使用适配器功能?

ArrayAdapter<String,String,String,RadiGroup> studList=new ArrayAdapter<String,String,String,RadiGroup>();

可以这样使用吗,以及如何为ListView开发定制化的Adapter ?

建议我最好的解决方案!

最佳答案

这是 ListView 的自定义适配器的示例。根据需要修改它: XML 布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/main"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">
    <!-- Header -->

    <LinearLayout
        android:id="@+id/header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/black" >

        <TextView
            android:id="@+id/item2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:height="30dip"
            android:text="Latest News - Your Healing Place"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="#FFFFFF"
            android:width="100dip" />

        <TextView
            android:id="@+id/item1"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:height="30dip"
            android:width="20dip" />

    </LinearLayout>

    <View android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="?android:attr/listDivider" />

    <LinearLayout android:id="@+id/layout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent">

        <ListView
            android:id="@+id/listview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:background="@color/black" >

        </ListView>

    </LinearLayout>
</LinearLayout>

新闻.java:

List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
String[] from = new String[] {"details", "date"};
int[] to = new int[] { R.id.item1, R.id.item2};
ListView lv= (ListView)findViewById(R.id.listview);
HashMap<String, String> map = new HashMap<String, String>();
map.put("details", "This is a sample message");
map.put("date", "24-07-2003");
fillMaps.add(map);

SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.grid_item, from, to);
lv.setAdapter(adapter);

关于android - Android中使用TextView、TextView、RadioGroup自定义ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15883152/

相关文章:

android - Eclipse FindBugs 插件因 Android 项目要求 java.rmi.remote 而失败

android - 标准C++库的跨平台程度如何?

android - HTML5 音频在 Android 平台上的 PhoneGap 中不起作用

android - 在 ArrayAdapter 中使用传递的上下文

android - ListView 在 Scroll 上显示错误的项目

android - 为什么 *.so 文件加载为静态代码?

android linearlayout on relativelayout 使 relative 消失

java - ListView 嵌套在 ListView 中,并且根据 Cursor 值不同行

android - 在 AlertDialog 中自定义 ListView

带有 CheckBox : setOnClickListener or setOnCheckedChangeListener 的 Android 自定义适配器