Android AppCompatEditText,AppCompatTextView, setText without ID

本小妞迷上赌 提交于 2020-11-29 03:54:05

问题


I have simple Login page with some textview and edittex and i set static text to textview and hint to edittext from string.xml working fine.

But Now

i am receiving that strings(which i set form stirng.xml as i explained above) form webservices and i have to set webservice string.

Issue is i didn't set any id to that login screen elements(edittext and textview).

Update

I have AppCompatTextView like below in my XML

   <androidx.appcompat.widget.AppCompatTextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="@dimen/_20sdp"
                android:gravity="center"
                android:text="@string/login_text_welcome"
                android:textColor="@color/colorTextLightGrey"
                android:textSize="@dimen/textview_size_medium"
                android:textStyle="bold" />

I want to settext to above AppCompatTextView without ID.

Is it possible to setText to textview and edittext without setting any id?


回答1:


Just include android:id="@+id/textView1 in your XML to set ID of an element.




回答2:


You can use findViewByName rather than findViewById and then continue with your code.



来源:https://stackoverflow.com/questions/64714568/android-appcompatedittext-appcompattextview-settext-without-id

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!