在自定义视图中设置文本
我根据在线教程创建了一个自定义课程。它工作得很好,但我想做的是让我可以设置视图的文本,就像我设置任何其他视图一样。这是如何实现的。这是自定义视图的 xml
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android: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>
我想要实现的是这个
FileView fileView = new FileView(this)
fileView.setText("text")
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"
android: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")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一方面,您可以使用提示为用户提供灰色文本提示,他们在输入文件名时不必删除该提示。在 XML 中,将 TextView 的
android:text
替换为android:hint
。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
withandroid:hint
for your TextView.将“File Name Here”替换为“TEXT YOU WANT”或@string/name_of_string_in_string.xml
或java方式,这是其他人回答的
replace "File Name Here" with "TEXT YOU WANT" or @string/name_of_string_in_string.xml
or the java way, which someone else answered
这里 no_internet 是包含 xml 视图。在包含视图中包含文本视图。您可以在包含自定义文本视图中设置文本,例如...
here no_internet is include xml view . in the include view contain text view. you can set text in include custom text view like ....