2013-07-25 3 views
0

선형 레이아웃의 Android를 기본보기로 만들고 싶습니다. 거기에는 각 행에 대한 수평 선형 레이아웃이 있고, 각 행에는 이미지와 설명, 가격 및 ID가 표시됩니다 (표시되지 않음).선형 레이아웃의 모든 콘텐츠를 클릭 가능한 항목으로 만드는 방법

일단 모든 항목에서 목록을 삭제하면 사용자가 행의 아무 곳이나 클릭 할 수 있기를 원합니다. 내가 어떻게 할 수 있니? 사용자 지정 목록보기를 원하는처럼

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:onClick="menuItemSelected" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/burger" /> 

    <TextView 
     android:id="@+id/editText1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:ems="10" 
     android:inputType="textMultiLine" 
     android:text="This a pictuer of a hamburger" /> 

    <TextView 
     android:id="@+id/editText2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.5" 
     android:ems="10" 
     android:inputType="numberDecimal" 
     android:text="R41.24" /> 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/tableRow12" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:clickable="true" 
    android:focusable="true" 
    android:onClick="menuItemSelected" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:contentDescription="Product Image" 
     android:src="@drawable/burger" /> 

    <TextView 
     android:id="@+id/editText21" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:ems="10" 
     android:inputType="textMultiLine" 
     android:text="This a pictuer of a hamburger" /> 

    <TextView 
     android:id="@+id/editText22" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_weight="0.5" 
     android:ems="10" 
     android:inputType="numberDecimal" 
     android:text="R41.24" /> 
</LinearLayout> 
+0

'onClick = "MenuItemSelected"와 동일하지 않습니까? – Zapnologica

답변

4

그것은 나에게 소리 : 여기

내 XML 코드입니다 : 내가있는 LinearLayout에 = 클릭 진정한 설정을 시도 How to make custom ListView

이 의지 스크롤 할 수 있고 클릭 할 수있는 콘텐츠 표를 만들 수 있습니다. 이를 사용자 정의하여 각 행에 원하는 방식으로 내용의 형식을 지정할 수 있습니다.

1

은 무엇을 달성하려고하는 것이 최선의 ListView를 사용하여 수행됩니다 : ListView Tutorial

당신은 ListView에, 어댑터와 그의 사용자 정의보기를 만들어야합니다. 이렇게하면 목록 항목의 ID뿐만 아니라 항목 자체를 얻을 수있는 OnListItemClickedListener를 가질 수 있습니다.

관련 문제