<Button android:id="@+id/button1" android:text="blah blah">
मैं android:text
के अंदर टेक्स्ट कैसे प्राप्त करूं?एक बटन के अंदर टेक्स्ट प्राप्त करें
<Button android:id="@+id/button1" android:text="blah blah">
मैं android:text
के अंदर टेक्स्ट कैसे प्राप्त करूं?एक बटन के अंदर टेक्स्ट प्राप्त करें
Button btn = (Button)findViewById(R.id.button1);
String buttontext = btn.getText().toString();
आशा है कि यह आपकी मदद करेगा।
आपको टेक्स्ट मिलता है।
Button button = (Button) findViewById(R.id.button1);
String yourText = (String)button.getText();
Button tv = (Button) findViewById(R.id.button1);
String buttonName = tv.getText().toString();
संपादित नीचे टिप्पणी के अनुसार, धन्यवाद :)।
TextView button1 = (TextView)findViewById(R.id.button1);
String text = button1.getText().toString();
Button mButton;
mButton=(Button)findViewById(R.id.button1);
String buttontext= mButton.getText().toString();
strings.xml में अपने सभी तार रखने की कोशिश करें (बजाय हार्ड-कोड उन्हें हर जगह)
<Button android:id="@+id/button1" android:text="@string/button1_label">
strings.xml में:
<string name="button1_label">blah blah</string>
फिर आप आसानी से टेक्स्ट प्राप्त कर सकते हैं:
Context.getString(R.string.button1_label)
आप और अधिक here देख सकते हैं।
tv.getText()। ToString(); अपेक्षित –