2011-09-16 23 views

Odpowiedz

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

Mam nadzieję, że to ci pomoże.

3

otrzymujesz tekst wg.

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(); 

Edit zgodnie z poniższym komentarzem, dzięki :).

+2

tv.getText(). ToString(); wymagany –

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

Postaraj się zachować wszystkie sznurki w strings.xml (zamiast twarde kodowania je wszędzie)

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

W strings.xml:

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

Następnie można łatwo uzyskać tekst za pomocą:

Context.getString(R.string.button1_label) 

Możesz dowiedzieć się więcej here.

Powiązane problemy