-2
   final RadioGroup radioGroup1 = (RadioGroup) findViewById(R.id.radiogroup);
              final TextView tv=(TextView) findViewById(R.id.textView1);   
        Button  mSubmitButton = (Button) findViewById(R.id.btnSubmit);
        relation.setOnItemSelectedListener(new CustomOnItemSelectedListener());
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        String text1;
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) 
            {
                RadioButton checkedRadioButton = (RadioButton) findViewById(checkedId);
               text1 = checkedRadioButton.getText().toString();

                Toast.makeText(getApplicationContext(), text1, Toast.LENGTH_SHORT).show();

            }
        });


        mSubmitButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                 String fName = first_name.getText().toString();
                 String re_lation = (String) relation.getSelectedItem(); 
                 String add_ress = address.getText().toString();
                  }

在我的 Onclick 函数中,我想从 onCheckedChanged 获取 text1 值。如何在我的 onclick 函数中获取 text1 值?

4

3 回答 3

3

将字符串 text1 声明为全局变量,例如,onCreate()活动的之前方法

String text1;

    @Override
    public void onCreate()
    {

    }
于 2012-06-21T11:01:25.110 回答
0

String text1;作为一个全局变量:

public class YourActvity extends Actvity {

   String text1;

   public onCreate( //...   

}
于 2012-06-21T10:59:59.703 回答
0

我认为您需要在类初始化下面初始化 text1 以便任何方法都可以使用此 text1 然后在一个方法中设置值并将值放入另一个方法中

public YourActvity extends Actvity {
String text1;
public method1(
set the value
}

public method1(
get the value
}
于 2012-06-21T11:03:58.440 回答