这个问题已经在这里有一个答案:
下面是我的EditText XML代码,我设置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" />
我想该ID以编程方式在我的活动类。
我想这个代码获取ID
int id=ettMId.getId();
但我得到下面的结果
If2131230797
其实我想这是我在XML设置了相同的ID名称(ettMId)
尝试这个
String stringID = ettMId.getResources().getResourceName(ettMId.getId());
然后你就可以做字符串操作提取的ID,这将是:id/
后的精确值