2014-09-14 3 views
2

다음과 같은 방법을 이해하는 데 어려움이 있습니다. the documentation에서, 방법의 설명은 다음과 같다 :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 (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. 

나는 마지막 두 이해하지만 parent 여기에 무엇을하는지 이해할 수 없었다 왜 view 필요합니까?

누군가 좋은 설명이 있으면 알려주세요.

답변

5

AdapterView는 ListView, GridView, Spinner 등일 수 있습니다. 이것은 Java에서 제네릭이라고합니다. 코드에서 parent를 사용하여 전체보기에 대해 작업을 수행 할 수 있습니다. 당신이있는 ListView를 사용한다면 예를 들어, 다음의 코드에 의해 전체 목록보기 숨길 수 :

parent.setVisibility(View.GONE); 

보기는 어댑터 뷰 AdapterView 내에서 특정 항목을 의미합니다. ListView에서 그것은 행입니다. 따라서 다음과 같이 말하여 행 내의 TextView에 대한 참조를 얻을 수 있습니다.

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

감사합니다. 부모님을 이해했습니다. 두 번째 사례에 대한 실질적인 예를 작성할 수 있습니까? – xyz

+0

어느 쪽? 보기? –

+0

예보기. – xyz