2011-09-16 7 views

答えて

9
Button btn = (Button)findViewById(R.id.button1); 
String buttontext = btn.getText().toString(); 

希望すると、これが役立ちます。

3

でテキストを取得します。

Button button = (Button) findViewById(R.id.button1); 
String yourText = (String)button.getText(); 
2
Button tv = (Button) findViewById(R.id.button1); 
String buttonName = tv.getText().toString(); 

編集以下のコメントによると、感謝:)。

+2

tv.getText()。toString();必須 –

3
TextView button1 = (TextView)findViewById(R.id.button1); 
String text = button1.getText().toString(); 
2
Button mButton; 
mButton=(Button)findViewById(R.id.button1); 
String buttontext= mButton.getText().toString(); 
1

(どこでもそれらをハードコーディングするのではなく)のstrings.xmlでのstrings.xmlで

<Button android:id="@+id/button1" android:text="@string/button1_label"> 

をすべての文字列を保つようにしてください:

<string name="button1_label">blah blah</string> 

次に、簡単にテキストを取得することができます:

Context.getString(R.string.button1_label) 

詳しくはhereをご覧ください。

関連する問題