2013-09-24 2 views
0

나는 내부에 사용자 정의 직선을 가진 3x3 gridview가 있습니다. 하지만이 같은 것을 원합니다. layout 그리고 인터넷에서 검색 할 때 열 범위 때문에 gridview를 사용할 수 없습니다. onClickListener 메서드 때문에 gridview를 사용했습니다. 사용자가 표 셀 중 하나를 클릭하면 새 활동이 시작됩니다 (동일한 활동이 아니므로 주 메뉴와 비슷합니다). TableLayout에서 할 수 있습니까? 따라서 셀을 스패닝 했더라도 onClick 메서드를 호출 할 수 있습니까? 나는 웹에서 몇 가지 해결책을 찾았지만, 내가 발견 한 모든 것은 tablerow (한 행에 3 개의 사용자 정의 레이아웃이 있다면 나에게 좋지 않다)를 클릭하는 것이다.안드로이드 tablelayout 셀 내용에 대한 클릭 리스너

TableLayout을위한 나의 레이아웃 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="@android:color/background_light" 
android:orientation="vertical" > 

<ImageView 
    android:id="@+id/headerPicture" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:contentDescription="@string/imageString" 
    android:src="@drawable/bicaj" /> 

<TableLayout 
    android:id="@+id/mainGrid" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:numColumns="3" > 

    <TableRow 
     android:id="@+id/mainFirstRow" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="5dip" > 

     <LinearLayout 
      android:id="@+id/mainOnline" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" > 
      <ImageView 
       android:id="@+id/mainIconOnline" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:contentDescription="@string/main_page_icon_descp" /> 

      <TextView 
       android:id="@+id/mainTextOnline" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textSize="12sp" /> 
     </LinearLayout> 
    </TableRow> 
. 
. 
. 
. 
    </TableLayout> 
</LinearLayout> 
+0

당신은 TableLayout에있는 모든 뷰에 대해 clickListener를 원합니까? – Manishika

+0

예. 두 번째 행의 두 번째 열의 항목에서 예를 클릭하면 새로운 활동이 시작됩니다. 그러나 예를 들어 세 번째 행의 세 번째 항목의 항목을 클릭하면 다른 활동이 시작됩니다. – Dandelion

답변

3

당신은 ImageView

..... 
    <LinearLayout 
       android:id="@+id/mainOnline" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" > 
       <ImageView 
        android:id="@+id/mainIconOnline" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:contentDescription="@string/main_page_icon_descp" /> 
...... 

에 그리고 당신의 활동에 clickListeners을 추가 할 수는

ImageView butt1 = (ImageView) findViewById(R.id.mainIconOnline); 

     butt1.setOnClickListener(this); 

@Override 
    public void onClick(View v) { 
     if (v.getId() == R.id.mainIconOnline) { 

      Intent i = new Intent(this, SecondActivityclass); 
     startActivity(i); 

     } 

    } 

이 작동합니다

+0

Button 대신 LinearLayouts에서 작동합니까? – Dandelion

+0

xml 레이아웃 게시 – Manishika

+0

내 질문을 업데이트했습니다. – Dandelion