Java 无法通过资源id检索值
我有以下几点:Java 无法通过资源id检索值,java,android,Java,Android,我有以下几点: <EditText android:id="@+id/kernelb11" android:layout_width="@dimen/matrixBoxWidthHeight" android:layout_height="@dimen/matrixBoxWidthHeight" android:layout_below="@+id/textView1" android:layout_marg
<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" >
由于总体要求,我无法使用findviewbyd()
此标识符指向R.id
资源,但需要R.string
资源标识符
您首先必须按id查找EditText
,然后获取其内容。大概是这样的:
String name = "kernelb11"
int a = this.getResources().getIdentifier(name, "id", getPackageName());
EditText et = (EditText)findViewById(a);
CharSequence asa = ed.getText();
尝试删除代码中的
此。
String name = "kernelb11";
int layoutID = getResources().getIdentifier(name, "id", getPackageName());
EditText et=(EditText)findViewById(R.id.kernelb11);这个不行吗?当你说你不能使用findViewById()时,你只是不能或不想使用?我不想。这是一个矩阵输入,
EditText
的总数可能从9到50不等。您能否说明由于什么原因不能使用findViewById()?
String name = "kernelb11"
int a = this.getResources().getIdentifier(name, "id", getPackageName());
EditText et = (EditText)findViewById(a);
CharSequence asa = ed.getText();
String name = "kernelb11";
int layoutID = getResources().getIdentifier(name, "id", getPackageName());