以编程方式获取 edittext 视图的 ID?
Get ID of edittext view programmatically?
这是我的 XML Edittext 代码,我用这个名字设置了 id ettMId
<EditText
android:id="@+id/ettMId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_hint_email_id"
android:imeOptions="actionNext"
android:inputType="text|textEmailAddress"
android:nextFocusDown="@id/etLPassword"
android:singleLine="true"
android:theme="@style/AppEditTextStyle" />
我想在我的 activity class 中以编程方式使用该 ID。
我试过这个代码来获取 id
int id=ettMId.getId();
但我得到的结果低于
If2131230797
实际上我想要与我在 XML
中设置的相同的 ID 名称(ettMId)
试试这个
String stringID = ettMId.getResources().getResourceName(ettMId.getId());
然后您可以进行字符串操作以提取将在 :id/
之后的 id 的确切值
这是我的 XML Edittext 代码,我用这个名字设置了 id ettMId
<EditText
android:id="@+id/ettMId"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/login_hint_email_id"
android:imeOptions="actionNext"
android:inputType="text|textEmailAddress"
android:nextFocusDown="@id/etLPassword"
android:singleLine="true"
android:theme="@style/AppEditTextStyle" />
我想在我的 activity class 中以编程方式使用该 ID。
我试过这个代码来获取 id
int id=ettMId.getId();
但我得到的结果低于
If2131230797
实际上我想要与我在 XML
中设置的相同的 ID 名称(ettMId)试试这个
String stringID = ettMId.getResources().getResourceName(ettMId.getId());
然后您可以进行字符串操作以提取将在 :id/