在 ListView 中显示 RadioGroup [英] Display RadioGroup in ListView

查看:31
本文介绍了在 ListView 中显示 RadioGroup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要知道如何将 RadioGroup 放入 ListView?

I need to know how can I put a RadioGroup in a ListView?

我是开发 android 的初学者.

I am a beginner at developing android.

我应该怎么做才能在 ListView 中显示 RadioGroup.
请指导我.

What should I do to display the RadioGroup in the ListView.
Please guide me.

这是我的代码:

enter code here
package com.mySample.Smpl1;


import android.os.Bundle;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView;
import android.app.*;
import android.view.View;
import android.widget.AdapterView.OnItemClickListener;

public class Smpl1 extends ListActivity
 {


  public void onCreate(Bundle savedInstanceState) 
   {
     super.onCreate(savedInstanceState);


     final String[] row = new  String []{"row1","row2"};
     setListAdapter(new ArrayAdapter<String>(this,R.layout.radiolayout,
             row));



     ListView lv = getListView();
     lv.setTextFilterEnabled(true);  

     lv.setOnItemClickListener(new OnItemClickListener()
     {

      public void onItemClick(AdapterView<?> parent,View eview,int position,long id)
         {
          Toast.makeText(getApplicationContext(), ((TextView)eview).getText(),
           Toast.LENGTH_SHORT).show();       

         }

     });



   }
}

这是我的 rowylayout.xml

and this is my rowylayout.xml

       <?xml version="1.0" encoding="UTF-8"?>

      <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/listView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:text="hahaha">`

     </TextView>



enter code here

我的 radio.xml

my radio.xml

enter code here

<?xml version="1.0" encoding="UTF-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content" >

<RadioGroup
    android:id="@+id/radioGroup1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:baselineAligned="false" >

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

    <RadioButton
        android:id="@+id/radio1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:checked="true"/>
   </RadioGroup>


 </LinearLayout>

推荐答案

<RadioGroup
android:id="@+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:baselineAligned="false" >

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

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

这个代码应该在 rowylayout.xml 文件中,它是列表项

this code should come inside rowylayout.xml file which is the list item

这篇关于在 ListView 中显示 RadioGroup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆