Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java McClick中的父视图和视图是什么?_Java_Android_Onitemclicklistener_Onitemclick - Fatal编程技术网

Java McClick中的父视图和视图是什么?

Java McClick中的父视图和视图是什么?,java,android,onitemclicklistener,onitemclick,Java,Android,Onitemclicklistener,Onitemclick,我很难理解下面的方法。其中,方法说明如下: public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id) Parameters: parent The AdapterView where the click happened. view The view within the AdapterView that was clicked (t

我很难理解下面的方法。其中,方法说明如下:

public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)


Parameters:
parent      The AdapterView where the click happened.
view        The view within the AdapterView that was clicked (this will be a view provided by the adapter)
position     The position of the view in the adapter.
id           The row id of the item that was clicked.
public-abstract-void-onItemClick(AdapterView父视图、视图视图、整型位置、长id)
参数:
设置发生单击的AdapterView的父级。
查看已单击的AdapterView中的视图(这将是适配器提供的视图)
在适配器中定位视图的位置。
id单击的项目的行id。
我理解最后两个,但不理解
parent
在这里做什么,以及为什么需要
view


如果有人有很好的解释,请让我理解。

AdapterView可以是ListView、GridView、Spinner等。这在Java中称为泛型。您可以在代码中使用父级对整个视图执行某些操作。例如,如果使用的是ListView,则可以通过以下代码行隐藏整个ListView:

parent.setVisibility(View.GONE);
该视图引用AdapterView中的特定项。在ListView中,它是行。因此,您可以通过如下方式获得对行内TextView的引用:

TextView myTextView = (TextView) view.findViewById(R.id.textView1);
String text = myTextView.getText().toString();

谢谢。现在我理解了家长的意思。你能写一个关于第二个的实例吗?@logx这个怎么样?TextView myTextView=(TextView)view.findViewById(R.id.textView1);String text=myTextView.getText().toString();那么,它是做什么的呢?是否用于引用“内”文本视图listview?是的,它是父视图中的子视图,因此父视图是更大的视图,如listview,它的子视图是更小的视图,如父视图中的TextView或ImageView,在本例中是listview是一个AdapterView,它用于在一个更大的视图中组合多个视图,但这取决于用途,这就是原因有时我们使用listview,有时使用GridView等。。。