I have a following element:
<EditText
android:id="@+id/kernelb11"
android:layout_width="@dimen/matrixBoxWidthHeight"
android:layout_height="@dimen/matrixBoxWidthHeight"
android:layout_below="@+id/textView1"
android:layout_margin="@dimen/marginOne"
android:background="@color/white1"
android:gravity="center"
android:inputType="numberSigned"
android:maxLength="2"
android:text="0" >
And i am trying to retrieve it in code like this but all its returning me is false
:
String name = "kernelb11"
int a = this.getResources().getIdentifier(name, "id", getPackageName());
CharSequence asa = this.getResources().getText(a); //Returning false
String as = (String) this.getResources().getText(a);
Due to overall requirment i cant use findViewById()
int a = this.getResources().getIdentifier(name, "id", getPackageName());
This identifier points to a R.id
resource, however Resources.getText(int)
expects a R.string
resource identifier.
You'll first have to find the EditText
by id and then get its contents. Something like this:
String name = "kernelb11"
int a = this.getResources().getIdentifier(name, "id", getPackageName());
EditText et = (EditText)findViewById(a);
CharSequence asa = ed.getText();
try by removing this.
in your code
String name = "kernelb11";
int layoutID = getResources().getIdentifier(name, "id", getPackageName());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.