[英]How to get the TextView and Button list from a view
First, sorry for my English and my knowledge, I'm a french Android Studio beginner.首先,对不起我的英语和知识,我是法国 Android Studio 初学者。
I've a view in a fragment named root: View root = inflater.inflate(R.layout.fragment_about, container, false);
我在一个名为 root 的片段中有一个视图:
View root = inflater.inflate(R.layout.fragment_about, container, false);
defined in onCreateView.在 onCreateView 中定义。 In this view, I've four buttons and four textview, each textview being assigned to a button.
在这个视图中,我有四个按钮和四个 textview,每个 textview 都分配给一个按钮。 And my idea is to hide and show the textview when the user click the assigned button.
我的想法是在用户单击分配的按钮时隐藏和显示 textview。
So I've defined an onClickListener for each button, and the parameter of this Listener is "this": mAboutPartButton1.setOnClickListener(this);
所以我为每个按钮定义了一个onClickListener,这个Listener的参数是“this”:
mAboutPartButton1.setOnClickListener(this);
. . So I suppose that "this" means the current view.
所以我想“这个”是指当前的观点。
I then set the onClick void whith a View parameter, and I would like get the Textview list present in the view to hide and show the appropriated Textview.然后,我使用 View 参数设置 onClick void,并且我想在视图中获取 Textview 列表以隐藏和显示适当的 Textview。
The problem is that I don't know how can I get this list of Textviews.问题是我不知道如何获得这个 Textviews 列表。
Thank you for all your answers !感谢您的所有回答!
onClick(View v) {
switch (v.getId()) {
case R.id.text1:
// do your stuff
break;
case R.id.text2:
//do your stuff
break;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.