2012-06-21 15 views
-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.how獲取text1值,以獲得我的onclick函數中的text1值?如何獲得Android中我的onclick函數中的字符串值?

回答

3

申報字符串的text1像全局變量,你的活動onCreate()方法之前

String text1; 

    @Override 
    public void onCreate() 
    { 

    } 
+0

裏面我的onclick函數,如何獲取String的text1值? – rajeshlawrance

+0

現在你可以在你的活動中的任何地方使用String text1 .. – user370305

0

String text1;作爲一個全局變量:

public class YourActvity extends Actvity { 

    String text1; 

    public onCreate(//... 

} 
+0

http://stackoverflow.com/a/11132605/804447 –

0

我認爲你需要初始化正下方的文本1類初始化,所以任何方法都可以使用此text1,然後在一個方法中設置該值並將該值轉換爲另一種方法

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

public method1(
get the value 
} 
相關問題