帮助需要为Android测验的应用程序 [英] Help needed for android quiz app

查看:105
本文介绍了帮助需要为Android测验的应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,只有最后一个选项文本正在改变Next按钮,其余的点击保持不变。有一些问题与环路我think.Can有人整理了这一点please.Thank你

下面是DB类:

 包com.myapps.quiz;

进口的java.io.File;
进口java.io.FileOutputStream中;
进口java.io.IOException异常;
进口的java.io.InputStream;
进口java.io.OutputStream中;

进口android.content.ContentValues​​;
进口android.content.Context;
进口android.database.Cursor;
进口android.database.SQLException;
进口android.database.sqlite.SQLiteDatabase;
进口android.database.sqlite.SQLiteException;
进口android.database.sqlite.SQLiteOpenHelper;

公共类DataBaseHelper扩展SQLiteOpenHelper {

    //而Android的默认系统应用程序的数据库路径。
    私有静态字符串DB_PATH =/data/data/com.myapps.quiz/databases/;
    私有静态字符串DB_NAME =测验;
    私有静态字符串TABLE_NAME =测验;

    私人SQLiteDatabase MyDatabase的;
    私人SQLiteDatabase myData的;
    私人最终语境myContext;

    / **
     *构造函数
     *注意到并保持传递的上下文中的一个参考,以便访问该应用程序的资产和资源。
     * @参数方面
     * /
    公共DataBaseHelper(上下文的背景下){
        超级(上下文,DB_NAME,空,1);
        this.myContext =背景;
    }



/ **
     *在系统上创建一个空数据库,并与自己的数据库重写它。
     * * /
    公共无效的CreateDatabase()抛出IOException异常{

        布尔dbExist = checkDataBase();
        如果(dbExist){
            //什么也不做 - 数据库中已存在
        }其他{
            CopyFiles();
        }
    }

    私人无效CopyFiles()
    {
        尝试
        {
           InputStream的是= myContext.getAssets()开(DB_NAME)。
           文件OUTFILE =新的文件(DB_PATH,DB_NAME);
           outfile.getParentFile()mkdirs()。
           outfile.createNewFile();

          如果(是== NULL)
          抛出新的RuntimeException(流为空);
          其他
          {
             FileOutputStream中出=新的FileOutputStream(OUTFILE);
          //的BufferedOutputStream OUT =新的BufferedOutputStream(新的FileOutputStream(OUTFILE));
              中byte buf [] =新的字节[128];
                做 {
              INT numread = is.​​read(BUF);
                    如果(numread&所述; = 0)
                        打破;
              out.write(BUF,0,numread);
               }而(真);

                is.close();
                out.close();
          }
           // AssetFileDescriptor AF = am.openFd(world_treasure_hunter_deluxe.apk);
        }
        赶上(IOException异常E)
        {
              抛出新的RuntimeException(E);
        }

    }

    / **
     *检查数据库中已存在,以避免重新复制每次打开应用程序时,该文件。
     * @返回true,如果它存在,虚假的,如果它不
     * /
    私人布尔checkDataBase(){

        SQLiteDatabase CHECKDB = NULL;

        尝试{
            字符串mypath中= DB_PATH + DB_NAME;
            CHECKDB = SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);

        }赶上(SQLiteException E){

        }

        如果(CHECKDB!= NULL){
            checkDB.close();
        }

        返回CHECKDB!= NULL?真假;
    }

    / **
     *复制你的数据库从当地的资产文件夹在刚才创建的空数据库
     *系统文件夹,从那里它可以被访问和处理。
     *这是通过transfering字节流进行。
     * * /
    私人无效copyDataBase()抛出IOException异常{

        //打开本地数据库作为输入流
        InputStream的myInput = myContext.getAssets()开(DB_NAME)。

        //路径刚刚创建的空分贝
        字符串outFileName = DB_PATH + DB_NAME;

        //打开空分贝的输出流
        的OutputStream myOutput =新的FileOutputStream(outFileName);

        //传输的字节从inputfile中的OUTPUTFILE
        byte []的缓冲区=新的字节[1024];
        INT长;
        而((长度= myInput.read(缓冲液))大于0){
            myOutput.write(缓冲液,0,长度);
        }

        //关闭流
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    公共无效的openDatabase()抛出的SQLException {

        //打开数据库
        字符串mypath中= DB_PATH + DB_NAME;
        MyDatabase的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);

    }

    @覆盖
    市民同步无效的close(){

            如果(MyDatabase的!= NULL)
                myDataBase.close();

            super.close();

    }

    @覆盖
    公共无效的onCreate(SQLiteDatabase DB){

    }

    @覆盖
    公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页){

    }



      ///取书的内容////////
      公共光标getQuiz_Content(INT BOOKID)
      {
        字符串mypath中= DB_PATH + DB_NAME;
        myData的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);

        光标CUR;
        CUR = myData.rawQuery(从测验选择quiz_text,其中quiz_id ='+ BOOKID +',NULL);
        cur.moveToFirst();

        myData.close();
        返回CUR;
      };
      //////////////////////////



      ///取书的内容////////
      公共光标getQuiz_List()
      {
        字符串mypath中= DB_PATH + DB_NAME;
        myData的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);
        INT I;

        光标CUR;
        CUR = myData.rawQuery(选择quiz_id,quiz_text,从测验correct_answer,NULL);
        cur.moveToFirst();
        I = cur.getCount();
        myData.close();
        返回CUR;
      };
      //////////////////////////


      公共光标getAns(INT quizid)
      {
          字符串mypath中= DB_PATH + DB_NAME;
          myData的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);

          光标CUR;
          CUR = myData.rawQuery(选择答案的答案,其中quiz_id ='+ quizid +',NULL);
          cur.moveToFirst();
          myData.close();
          返回CUR;
      }

      公共光标getAnsList()
      {
          字符串mypath中= DB_PATH + DB_NAME;
          myData的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READONLY);

          光标CUR;
          CUR = myData.rawQuery(选择答案的答案,NULL);
          cur.moveToFirst();
          myData.close();

          返回CUR;
      }



      // ---更新一个标题---
     / *公共布尔UpdateFavourite_Individual(长ROWID,串最爱)
      {
        字符串mypath中= DB_PATH + DB_NAME;
        myData的= SQLiteDatabase.openDatabase(mypath中,空,SQLiteDatabase.OPEN_READWRITE);

          ContentValues​​的args =新ContentValues​​();
          args.put(书签,喜欢的);
          返回myData.update(歌词,指定参数时,
                           ROWID =+ ROWID,NULL)> 0;
      } * /
      //////////////////


}
 

下面是Quiz.java:

 包com.myapps.quiz;

进口java.io.IOException异常;



进口android.app.Activity;
进口android.database.Cursor;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.widget.Button;
进口android.widget.LinearLayout;
进口android.widget.RadioButton;
进口android.widget.RadioGroup;
进口android.widget.TextView;

公共类测验延伸活动{
    / **第一次创建活动时调用。 * /
    最后DataBaseHelper DB =新DataBaseHelper(本);

    光标C3;
    光标C4;
    INT计数器= 1;
    字符串标签;


    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
        字符串选项[] =新的String [19];
     //获取是无线电集团布局
        RadioGroup中RadioGroup中=(RadioGroup中)findViewById(R.id.rdbGp1);
        //布局PARAMS来增加每个单选按钮时使用
        LinearLayout.LayoutParams的LayoutParams =新RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);


        C4 = db.getAnsList();
        c4.moveToFirst();
        为(中间体K = 0; K&所述19; k ++)
        {
            项[K] = c4.getString(0);
            c4.moveToNext();
            Log.e(值,选项[K]);
        }

        的for(int i = 0;我4;;我++){
            最后单选newRadioButton =新的单选按钮(这一点);
            C3 = db.getAns(3);

        对于(INT J = 0; J<我; J ++)
            c3.moveToNext();
           标记= c3.getString(0);

        newRadioButton.setText(标签);
        newRadioButton.setId(6);
        radiogroup.addView(newRadioButton,的LayoutParams);
        // getOptions();



        尝试 {
            db.createDataBase();
            db.openDataBase();
        }赶上(IOException异常E){
            // TODO自动生成的catch块
            e.printStackTrace();
        }
        最后光标C1;

        C1 = db.getQuiz_Content(柜);






        //rdoAns1.setText("Lisbon);

        最后的TextView tvQuizText =(TextView中)findViewById(R.id.TextView01);
        tvQuizText.setText(c1.getString(0));

        按钮btnNext =(按钮)findViewById(R.id.btnNext);
        btnNext.setOnClickListener(新View.OnClickListener(){


            @覆盖
            公共无效的onClick(视图v){
                // TODO自动生成方法存根

                    游标c2 = NULL;
                    光标C3 = NULL;

                    如果(计数器小于5)
                    {
                    计数器+ = 1;
                    C2 = db.getQuiz_Content(柜);
                    C3 = db.getAns(柜);
                    后//Log.e("Row位置增量,Integer.toString(c2.getPosition()));
                    tvQuizText.setText(c2.getString(0));
                    }



                    为(诠释J = 0; J&所述; 3; J ++)
                    {
                        c3.moveToNext();
                       标记= c3.getString(0);

                    newRadioButton.setText(标签);

                    }

                    //Log.e("value:",Integer.toString(counter));
                    //Log.e("value",c3.getString(0));
            }
        });
        // C3 = db.getAns(4);
     // rdoAns1.setText(c3.getString(0));
      //rdoAns2.setText(c3.getString(1));
      //rdoAns3.setText(c3.getString(2));
      //rdoAns4.setText(c3.getString(3));
    }
    / **添加单选按钮组* /
   //私人无效getOptions()
    {

        //获取是无线电集团布局
        // RadioGroup中RadioGroup中=(RadioGroup中)findViewById(R.id.rdbGp1);
        //布局PARAMS来增加每个单选按钮时使用
        //LinearLayout.LayoutParams的LayoutParams =新RadioGroup.LayoutParams(
          // RadioGroup.LayoutParams.WRAP_CONTENT,
            // RadioGroup.LayoutParams.WRAP_CONTENT);

        //增加20单选按钮组

        //的for(int i = 0;我4;;我++){
          //单选newRadioButton =新的单选按钮(这一点);
           // C3 = db.getAns(4);
        //为(INT J = 0; J<我; J ++)
          // c3.moveToNext();
           //字符串标签= c3.getString(0);

        //newRadioButton.setText(label);
        //newRadioButton.setId(i);
        //radiogroup.addView(newRadioButton,的LayoutParams);
        }

    }

    }
 

下面是我的XML布局:

 < AbsoluteLayout机器人:ID =@ + ID / AbsoluteLayout01机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT的xmlns:机器人=HTTP://模式.android.com / APK / RES / Android的>


                < RadioGroup中
                机器人:ID =@ + ID / rdbGp1
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =WRAP_CONTENT
                机器人:layout_y =30dip
                的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
                机器人:方向=垂直
                >
                < / RadioGroup中>


<按钮的android:文本=保存机器人:ID =@ + ID / btnSave机器人:layout_width =100dip机器人:layout_height =WRAP_CONTENT机器人:layout_x =50dip机器人:layout_y =250dip&GT ;< /按钮>
<按钮的android:文本=下一步机器人:ID =@ + ID / btnNext机器人:layout_width =100dip机器人:layout_height =WRAP_CONTENT机器人:layout_x =175dip机器人:layout_y =250dip&GT ;< /按钮>

< TextView的Andr​​oid版本:layout_x =17dip机器人:layout_y =15dip机器人:ID =@ + ID / TextView01机器人:layout_width =WRAP_CONTENT机器人:文本=@ + ID / TextView01机器人:layout_height = WRAP_CONTENT>< / TextView的>






< / AbsoluteLayout>
 

解决方案

如果我得到这个权利,而code是有点困惑与所有这些大括号,你在for循环创建单选按钮?创建newRadioButton并将其添加到布局。之后,对于完成后,你有newRadioButton那是你创建的最后一个。当你尝试在NewRadioButton设置文本,你唯一要做的是在同一个单选按钮设置文本3倍。

所以,你必须让每一个单选按钮单独地,用他们的RadioGroup中。

我希望帮助。

MY issue is that only the last option text is changing on the click of the Next button and the rest remain same. There is some problem with the loop i think.Can someone sort this out please.Thank you

Here's the db class:

package com.myapps.quiz;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHelper extends SQLiteOpenHelper{

    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.myapps.quiz/databases/";
    private static String DB_NAME = "quiz";
    private static String Table_name="Quiz";

    private SQLiteDatabase myDataBase; 
    private SQLiteDatabase myData; 
    private final Context myContext;

    /**
     * Constructor
     * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
     * @param context
     */
    public DataBaseHelper(Context context) {
        super(context, DB_NAME, null, 1);
        this.myContext = context;
    }   



/**
     * Creates a empty database on the system and rewrites it with your own database.
     * */
    public void createDataBase() throws IOException{

        boolean dbExist = checkDataBase();
        if(dbExist){
            //do nothing - database already exist
        }else{  
            CopyFiles();
        }
    }

    private void CopyFiles()
    {
        try
        { 
           InputStream is = myContext.getAssets().open(DB_NAME); 
           File outfile = new File(DB_PATH,DB_NAME);
           outfile.getParentFile().mkdirs();
           outfile.createNewFile();

          if (is == null)
          throw new RuntimeException("stream is null");
          else
          {
             FileOutputStream out = new FileOutputStream(outfile);      
          // BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(outfile));
              byte buf[] = new byte[128];
                do {
              int numread = is.read(buf);
                    if (numread <= 0)
                        break;
              out.write(buf, 0, numread);
               } while (true);

                is.close();
                out.close();
          }
           //AssetFileDescriptor af = am.openFd("world_treasure_hunter_deluxe.apk");
        }
        catch (IOException e)
        {
              throw new RuntimeException(e); 
        }

    }    

    /**
     * Check if the database already exist to avoid re-copying the file each time you open the application.
     * @return true if it exists, false if it doesn't
     */
    private boolean checkDataBase(){

        SQLiteDatabase checkDB = null;

        try{
            String myPath = DB_PATH + DB_NAME;
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

        }catch(SQLiteException e){

        }

        if(checkDB != null){
            checkDB.close();
        }

        return checkDB != null ? true : false;
    }

    /**
     * Copies your database from your local assets-folder to the just created empty database in the
     * system folder, from where it can be accessed and handled.
     * This is done by transfering bytestream.
     * */
    private void copyDataBase() throws IOException{

        //Open your local db as the input stream
        InputStream myInput = myContext.getAssets().open(DB_NAME);

        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;

        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);

        //transfer bytes from the inputfile to the outputfile
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer))>0){
            myOutput.write(buffer, 0, length);
        }

        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();

    }

    public void openDataBase() throws SQLException{

        //Open the database
        String myPath = DB_PATH + DB_NAME;
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

    }

    @Override
    public synchronized void close() {

            if(myDataBase != null)
                myDataBase.close();

            super.close();

    }

    @Override
    public void onCreate(SQLiteDatabase db) {

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }



      /// Get Book content////////
      public Cursor getQuiz_Content(int bookId)     
      {
        String myPath = DB_PATH + DB_NAME;
        myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);       

        Cursor cur;
        cur=myData.rawQuery("select quiz_text from Quiz where quiz_id='"+bookId+"'",null);
        cur.moveToFirst();

        myData.close();
        return cur;
      };
      //////////////////////////



      /// Get Book content////////
      public Cursor getQuiz_List()     
      {
        String myPath = DB_PATH + DB_NAME;
        myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);       
        int i;

        Cursor cur;
        cur=myData.rawQuery("select quiz_id,quiz_text,correct_answer from quiz",null);
        cur.moveToFirst();
        i = cur.getCount();
        myData.close();
        return cur;
      };
      //////////////////////////


      public Cursor getAns(int quizid)
      {
          String myPath = DB_PATH + DB_NAME;
          myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

          Cursor cur;
          cur = myData.rawQuery("select answers from answer where quiz_id='"+quizid+"'", null);
          cur.moveToFirst();
          myData.close();
          return cur;
      }

      public Cursor getAnsList()
      {
          String myPath = DB_PATH + DB_NAME;
          myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);

          Cursor cur;
          cur = myData.rawQuery("select answers from answer", null);
          cur.moveToFirst();
          myData.close();

          return cur;  
      }



      //---updates a title---
     /* public boolean UpdateFavourite_Individual(long rowid,String fav) 
      {
        String myPath = DB_PATH + DB_NAME;
        myData = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

          ContentValues args = new ContentValues();
          args.put("bookmark", fav);
          return myData.update("lyrics", args, 
                           "rowid=" + rowid, null) > 0;                     
      }*/
      //////////////////


}

Here's Quiz.java:

    package com.myapps.quiz;

import java.io.IOException;



import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

public class Quiz extends Activity{
    /** Called when the activity is first created. */
    final DataBaseHelper db = new DataBaseHelper(this);

    Cursor c3;
    Cursor c4;
    int counter=1;  
    String label;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        String options[] = new String[19];
     // get reference to radio group in layout
        RadioGroup radiogroup = (RadioGroup) findViewById(R.id.rdbGp1);
        // layout params to use when adding each radio button
        LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
                RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT);


        c4 = db.getAnsList();
        c4.moveToFirst();
        for (int k=0;k<19;k++)
        {       
            options[k]=c4.getString(0);
            c4.moveToNext();
            Log.e("value:", options[k]);
        }

        for (int i = 0; i < 4; i++){
            final RadioButton newRadioButton = new RadioButton(this);
            c3 = db.getAns(3);

        for (int j=0;j<i;j++)    
            c3.moveToNext();
           label = c3.getString(0);

        newRadioButton.setText(label);
        newRadioButton.setId(6);
        radiogroup.addView(newRadioButton, layoutParams);
        //getOptions();



        try {
            db.createDataBase();
            db.openDataBase();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        final Cursor c1;

        c1= db.getQuiz_Content(counter);






        //rdoAns1.setText("Lisbon");

        final TextView tvQuizText = (TextView)findViewById(R.id.TextView01);
        tvQuizText.setText(c1.getString(0));

        Button btnNext = (Button)findViewById(R.id.btnNext);
        btnNext.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                    Cursor c2 = null ;
                    Cursor c3 =null;    

                    if (counter < 5)
                    {
                    counter +=1;    
                    c2 = db.getQuiz_Content(counter);
                    c3 = db.getAns(counter);
                    //Log.e("Row Position after increment:",Integer.toString(c2.getPosition()));
                    tvQuizText.setText(c2.getString(0));
                    }



                    for (int j=0;j<3;j++)    
                    {   
                        c3.moveToNext();
                       label = c3.getString(0);

                    newRadioButton.setText(label);

                    }

                    //Log.e("value:",Integer.toString(counter));
                    //Log.e("value",c3.getString(0));
            }
        });
        //c3 = db.getAns(4);
     // rdoAns1.setText(c3.getString(0));
      //rdoAns2.setText(c3.getString(1));
      //rdoAns3.setText(c3.getString(2));
      //rdoAns4.setText(c3.getString(3));
    }
    /** add radio buttons to the group */
   // private void getOptions()
    {

        // get reference to radio group in layout
        //RadioGroup radiogroup = (RadioGroup) findViewById(R.id.rdbGp1);
        // layout params to use when adding each radio button
        //LinearLayout.LayoutParams layoutParams = new RadioGroup.LayoutParams(
          //      RadioGroup.LayoutParams.WRAP_CONTENT,
            //    RadioGroup.LayoutParams.WRAP_CONTENT);

        // add 20 radio buttons to the group

        //for (int i = 0; i < 4; i++){
          //  RadioButton newRadioButton = new RadioButton(this);
           // c3 = db.getAns(4);
        //for (int j=0;j<i;j++)    
          //  c3.moveToNext();
           // String label = c3.getString(0);

        //newRadioButton.setText(label);
        //newRadioButton.setId(i);
        //radiogroup.addView(newRadioButton, layoutParams);
        }

    }

    }

Here's my XML layout:

<AbsoluteLayout android:id="@+id/AbsoluteLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android">


                <RadioGroup
                android:id="@+id/rdbGp1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_y="30dip"
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                >
                </RadioGroup>


<Button android:text="Save" android:id="@+id/btnSave" android:layout_width="100dip" android:layout_height="wrap_content" android:layout_x="50dip" android:layout_y="250dip"></Button>
<Button android:text="Next" android:id="@+id/btnNext" android:layout_width="100dip" android:layout_height="wrap_content" android:layout_x="175dip" android:layout_y="250dip"></Button>

<TextView android:layout_x="17dip" android:layout_y="15dip" android:id="@+id/TextView01" android:layout_width="wrap_content" android:text="@+id/TextView01" android:layout_height="wrap_content"></TextView>






</AbsoluteLayout>

解决方案

If I got this right, and the code is a little confusing with all those curly brackets, you create RadioButtons in for loop? You create newRadioButton and add it to layout. After that for finishes, you have newRadioButton that is the last one you created. And when you try to set text on NewRadioButton, the only thing you do is setting text on the same radio button 3 times.

So you have to get each RadioButton individually, using their RadioGroup.

I hope that helped.

这篇关于帮助需要为Android测验的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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