0

我有以下元素:

 <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" >

我正试图用这样的代码检索它,但它返回给我的只是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);

由于总体要求,我无法使用findViewById()

4

2 回答 2

1
int a = this.getResources().getIdentifier(name, "id", getPackageName());

这个标识符指向一个R.id资源,但是Resources.getText(int)需要一个R.string资源标识符。

您首先必须找到EditTextby id,然后获取其内容。像这样的东西:

String name = "kernelb11"
int a = this.getResources().getIdentifier(name, "id", getPackageName());
EditText et = (EditText)findViewById(a);
CharSequence asa =  ed.getText();
于 2013-11-06T10:02:43.203 回答
0

尝试this.在您的代码中删除

String name = "kernelb11";

int layoutID = getResources().getIdentifier(name, "id", getPackageName());
于 2013-11-06T10:03:34.987 回答