2011-12-28 7 views
5

첫 번째 행에 안드로이드, 두 번째 행에 검은 딸기, 세 번째 행에 아이폰이 있다고 가정하는 내용의 ListView가 있습니다. ListView의 전체 행을 클릭 할 수있게 만들고 싶지만 위에 클릭하면됩니다. 목록보기 행의 내용 다음은 이벤트를 클릭 수행하지만 다음 클릭 동작은 목록보기 클릭을 만들기위한 performed.My 코드해야 행의 어느 곳을 클릭하면 내가 원하는 것은 다음과 같습니다 : XML에listview에서 전체 행을 클릭 할 수있게 만드는 방법

public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.listartistspacedetailview); 

    setListAdapter(new ArrayAdapter(this,R.layout.listitem_layout,R.id.barrio, keywordxmlparsing.array_artistname)); 

} 
@Override 
protected void onListItemClick(ListView l, View v, int position, long thisID) 
{ 
    Intent i = new Intent(Artistspacedetailview.this, Loadingimagetab.class); 
    startActivity(i); 
} 

및 ListView에 태그 파일 :

<ListView 
    android:clickable="true" 
    android:layout_marginLeft="10dip" 
    android:layout_marginRight="10dip" 
    android:id="@+id/android:list" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:layout_below="@id/horizontolline" 
    android:cacheColorHint="#00000000" 
    android:drawSelectorOnTop="false" /> 
+4

귀하의 질문은 아직 명확하지 않습니다. listitem을 클릭하면 아마도 원시 (클릭 이벤트를 잡아야 함)를 선택해야합니다. 그게 무슨 문제인지 분명하지 않습니다! – Hiral

+0

listitem_layout을 게시하십시오. – Ian

+0

나는 목록에서 iten을 클릭하면 목록 행 만 클릭 할 수 있다는 것을 의미합니다. 현명한 다른 클릭 이벤트는 fire.even이 아닙니다. android : clickable = "true"를 정의하고 채우기 부모로 목록보기의 너비를 지정합니다. – shyam

답변

-2

이것은 사용자에게 도움이 될 수 있습니다.

listView.setOnItemClickListener(new OnItemClickListener() { 
@Override 
public void onItemClick(AdapterView<?> list, View view, int position, long id) { 
      //code to be executed. 
    } 

} 
}); 
8

이 질문은 오래 알고 있지만, 나는이 문제에 대한보고되었을 때이 구글에서 나를 위해 처음으로 히트했다.

이것은 내 해결책입니다.

<ListView 
    android:id="@+id/XXXXXX" 
    android:layout_width="fill_parent" // Changed from wrap content 
    android:layout_height="fill_parent" // Changed from wrap content 
    android:clickable="true" >   // This was suggested in other topics 
</ListView> 
2

이것은 오래되었지만 다른 사람에게는 도움이 될 수 있습니다. 부모를 채우기 위해 풍선 레이아웃을 설정하고 레이아웃 내부에서 클릭 할 수있는 다른 항목으로 설정하여 목록 항목이 모든 포커스를 얻을 수 있도록합니다. 또한 항목을 focusable false 및 focusableOnTouch false로 설정합니다.

관련 문제