在android中更改textview的值

在android中更改textview的值,android,Android,我是新来的,也是android开发的。我的代码有问题 我想,当我点击广播组的文本文本视图必须改变。但这并没有发生。有人能帮我吗 这是我的密码 package com.example.mine4.truefalse; 导入android.app.Activity; 导入android.content.Intent; 导入android.os.SystemClock; 导入android.os.Bundle; 导入android.os.Handler; 导入android.util.Log; 导入

我是新来的,也是android开发的。我的代码有问题 我想,当我点击广播组的文本文本视图必须改变。但这并没有发生。有人能帮我吗

这是我的密码

package com.example.mine4.truefalse;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.SystemClock;
导入android.os.Bundle;
导入android.os.Handler;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.Button;
导入android.widget.DigitalClock;
导入android.widget.EditText;
导入android.widget.RadioButton;
导入android.widget.RadioGroup;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.text.DateFormat;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Calendar;
公共类新游戏扩展活动{
int min=1;
int max=20;
int randm=(int)(Math.random()*max)+min;
文本视图级;
text查看时钟,text;
放射组rg1;
int pos1,pos2,AVal,j=0;
收音机按钮收音机1,收音机2;
QueryClass qc=新的QueryClass(本);
int correct=0;
int错误=0;
串q;
ArrayList QVal;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u new\u游戏);
text=(TextView)findViewById(R.id.textv);
radio1=(RadioButton)findViewById(R.id.radio1);
radio2=(RadioButton)findViewById(R.id.radio2);
rg1=(放射组)findViewById(R.id.rg1);
qc.open();
AVal=qc.getANSData(randm);
QVal=qc.getQueData(randm);
q=(字符串)QVal.get(j);
text.setText(q);
qc.close();
rg1.setOnCheckedChangeListener(新的RadioGroup.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(RadioGroup组,int checkedId){
//TODO自动生成的方法存根
pos1=rg1.indexOfChild(findviewbyd(checkedId));
pos2=rg1.indexOfChild(findViewById(rg1.getCheckedRadioButtonId());
}
});
rg1.setOnCheckedChangeListener(新的RadioGroup.OnCheckedChangeListener(){
@凌驾
检查更改后的公共无效(RadioGroup组,int checkedId){
//TODO自动生成的方法存根
pos1=rg1.indexOfChild(findviewbyd(checkedId));
pos2=rg1.indexOfChild(findViewById(rg1.getCheckedRadioButtonId());
if(pos2==AVal){
正确的++;
setText(“吃15个费列罗罗彻的最快时间是1分10秒。”);
}
else if(pos2!=AVal){
setText(“吃15个费列罗罗彻的最快时间是1分10秒。”);
错误++;
//Toast.makeText(NewGame.this,错误+“”,Toast.LENGTH_LONG.show();
}
Toast.makeText(NewGame.this,pos2+“”,Toast.LENGTH_SHORT).show();
检查();
}
});
}
公共作废检查(){
if(pos2==AVal){
正确的++;
//Toast.makeText(NewGame.this,correct+“”,Toast.LENGTH_LONG.show();
}
else if(pos2!=AVal){
错误++;
//Toast.makeText(NewGame.this,错误+“”,Toast.LENGTH_LONG.show();
}
}
@凌驾
公共布尔onCreateOptions菜单(菜单){
//为菜单充气;这会将项目添加到操作栏(如果存在)。
getMenuInflater().充气(R.menu.menu\u new\u游戏,菜单);
返回true;
}
@凌驾
公共布尔值onOptionsItemSelected(菜单项项){
//处理操作栏项目单击此处。操作栏将
//自动处理Home/Up按钮上的点击,只要
//在AndroidManifest.xml中指定父活动时。
int id=item.getItemId();
//noinspection SimplifiableIf语句
if(id==R.id.action\u设置){
返回true;
}
返回super.onOptionsItemSelected(项目);
}
@凌驾
public void onBackPressed()
{
//在此代码显示对话框
super.onBackPressed();//根据需要可选
Intent intn=newintent(NewGame.this,Exmain.class);
星触觉(intn);
}

}
我已更改了您的代码。。现在检查

package com.example.mine4.truefalse;
import android.app.Activity;
import android.content.Intent;
import android.os.SystemClock;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.DigitalClock;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

public class NewGame extends Activity {
    int min = 1;
    int max = 20;
    int randm = (int)(Math.random() * max) + min;
    TextView level;
    Button b1;
    TextView text;
    RadioGroup rg1;
    int pos1=0,pos2,AVal,j=0;
    RadioButton radio1,radio2;
    QueryClass qc = new QueryClass(this);

    int correct=0;
    int wrong=0;
    String q;
    ArrayList QVal;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new_game);
        text = (TextView) findViewById(R.id.textv);
        b1=(Button)findViewById(R.id.b1);
//        radio1 = (RadioButton) findViewById(R.id.radio1);
//        radio2 = (RadioButton) findViewById(R.id.radio2);
//        rg1 = (RadioGroup) findViewById(R.id.rg1);
        qc.open();
        AVal = qc.getANSData(randm);
        QVal = qc.getQueData(randm);

            q = (String) QVal.get(j);
            text.setText(q);
             qc.close();
            b1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    for(j=0;j<QVal.size();j++) {
                        if(pos1<9) {
                            text.setText((String) QVal.get(j));
                            pos1++;
                        }
                    }
                }
            });
                }
    public void Check(){
        if(pos2==AVal){
            correct++;
            //Toast.makeText(NewGame.this,correct+"",Toast.LENGTH_LONG).show();
        }
        else if(pos2!=AVal) {
            wrong++;
           // Toast.makeText(NewGame.this,wrong+"",Toast.LENGTH_LONG).show();
        }
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_new_game, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
    @Override
    public void onBackPressed()
    {
        // code here to show dialog
        super.onBackPressed();  // optional depending on your needs
        Intent intn = new Intent(NewGame.this,Exmain.class);
        startActivity(intn);
    }
}
package com.example.mine4.truefalse;
导入android.app.Activity;
导入android.content.Intent;
导入android.os.SystemClock;
导入android.os.Bundle;
导入android.os.Handler;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.Button;
导入android.widget.DigitalClock;
导入android.widget.EditText;
导入android.widget.RadioButton;
导入android.widget.RadioGroup;
导入android.widget.TextView;
导入android.widget.Toast;
导入java.text.DateFormat;
导入java.text.simpleDataFormat;
导入java.util.ArrayList;
导入java.util.Calendar;
公共类新游戏扩展活动{
int min=1;
int max=20;
int randm=(int)(Math.random()*max)+min;
文本视图级;
按钮b1;
文本查看文本;
放射组rg1;
int pos1=0,pos2,AVal,j=0;
收音机按钮收音机1,收音机2;
QueryClass qc=新的QueryClass(本);
int correct=0;
int错误=0;
串q;
ArrayList QVal;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u new\u游戏);
text=(TextView)findViewById(R.id.textv);
b1=(按钮)findViewById(R.id.b1);
//radio1=(RadioButton)findV
RadioGroup rg1=(RadioGroup) findViewById(R.id.rg1);

    rg1.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        public void onCheckedChanged(RadioGroup group, int checkedId) 
        {
            if(radio1.isChecked())
            {
                   text.setText("The fastest time to eat 15 Ferrero Rocher is 1 minute 10 seconds.");  //or what you want to stay inyour textView
            }
            else if(radio2.isChecked())
            {
                   text.setText("The fastest time to eat 15 Ferrero Rocher is 1 minute 10 seconds."); //or what you want to stay inyour textView
            }
         }
    });
rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                pos1 = rg1.indexOfChild(findViewById(checkedId));
                pos2 = rg1.indexOfChild(findViewById(rg1.getCheckedRadioButtonId()));

            }


        });
        rg1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                // TODO Auto-generated method stub
                pos1 = rg1.indexOfChild(findViewById(checkedId));
                pos2 = rg1.indexOfChild(findViewById(rg1.getCheckedRadioButtonId()));
                if(pos2==AVal){
                    correct++;
                    text.setText("The fastest time to eat 15 Ferrero Rocher is 1 minute 10 seconds.");
                }
                else if(pos2!=AVal) {
                  text.setText("The fastest time to eat 15 Ferrero Rocher is 1 minute 10 seconds.");

                    wrong++;
                    // Toast.makeText(NewGame.this,wrong+"",Toast.LENGTH_LONG).show();
                }
                Toast.makeText(NewGame.this,pos2+"",Toast.LENGTH_SHORT).show();
                Check();
            }


        });
RadioGroup rg1;
TextView text;
text = (TextView) findViewById(R.id.textv);
rg1= (RadioGroup) findViewById(R.id.rg1);



    rg1.setOnCheckedChangeListener(new OnCheckedChangeListener() {



        @Override

        public void onCheckedChanged(RadioGroup group, int checkedId) {

            // find which radio button is selected

            if(checkedId == R.id.radio1) {
              text.setText("Radio 1 selected");
                Toast.makeText(getApplicationContext(), "Radio 1 selected",Toast.LENGTH_SHORT).show();

            } else if(checkedId == R.id.radio2) {

                text.setText("Radio 2 selected");
                Toast.makeText(getApplicationContext(), "Radio 2 selected",Toast.LENGTH_SHORT).show();

            } else {

                //do something when nothing selected

            }

        }



    });