开发者

setText in custom view

开发者 https://www.devze.com 2023-02-17 13:16 出处:网络
I have created a custom class from a tutorial online. It works fine, but what I want to do is make it so that I can set the text of the view, just like I would any other view. How is that accomplished

I have created a custom class from a tutorial online. It works fine, but what I want to do is make it so that I can set the text of the view, just like I would any other view. How is that accomplished. Here is the xml for the custom view

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
a开发者_StackOverflowndroid:layout_height="wrap_content"
android:gravity="center">
<ImageView
android:id="@+id/file_image_holder"
android:layout_width="110dip"
android:layout_height="110dip"
android:src="@drawable/pdf_icon" />
<TextView
android:id="@+id/file_name_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="File Name Here" />
</LinearLayout>

What I am trying to achieve is this

FileView fileView = new FileView(this)
fileView.setText("text")


TextView filename = (TextView)findViewById(R.id.file_name_holder);
filename.setText("someFile.exe");

On another note ... you can use hint to give your users a greyed out text prompt that they won't have to erase when entering a filename. In your XML replace android:text with android:hint for your TextView.


replace "File Name Here" with "TEXT YOU WANT" or @string/name_of_string_in_string.xml

or the java way, which someone else answered


here no_internet is include xml view . in the include view contain text view. you can set text in include custom text view like ....

 no_internet     = view.findViewById(R.id.no_internet);
  ((TextView) no_internet).setText(R.string.no_internet_connection);
0

精彩评论

暂无评论...
验证码 换一张
取 消