2011-04-06 5 views
0

Google의 android-developer 포럼에 같은 질문을 게시했습니다. 여기에서 반복 중입니다 :ListViews inside TableLayout

하나의 TableRow가있는 TableLayout이 있습니다. 첫 번째 열/셀은 ListView입니다. 두 번째 셀/열은 두 개의 ListView로 구성된 TableLayout입니다.

xml 레이아웃을 부 풀릴 때 모든 것이 잘 보이고 각 ListView에 대해 개의 어댑터가 설정되었습니다.

나는 어댑터를 통해 이러한 목록에 더미 요소를 추가했으며 은 목록을 위아래로 스크롤 할 수 있습니다.

하지만 onItemClick이 실행되지 않습니다.

다음

내 레이아웃 파일입니다 -

그리고 자바 파일에서, 내가

ListView lv = (ListView) findViewById(R.id.listView1); 
    lv.setAdapter(new EfficientAdapterLeft(this)); 
    lv.setOnItemClickListener(new OnItemClickListener() 

{ @Override 공공 무효 onItemClick 할

<RelativeLayout android:id="@+id/top_header" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 
      <Button 
        android:text="Edit" 
        android:id="@+id/button1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"> 
      </Button> 
      <TextView 
        android:text="dummy1" 
        android:textStyle="bold" 
        android:id="@+id/textView3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_toRightOf="@+id/button1" 
        android:layout_centerVertical="true" 
        android:paddingLeft="25dip" 
        android:textSize="18dip"> 
      </TextView> 
      <Button 
        android:id="@+id/button2" 
        android:layout_alignParentTop="true" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:text="Cancel" 
        android:layout_alignParentRight="true"> 
      </Button> 
      <TextView 
        android:layout_alignParentTop="true" 
        android:text="dummy2" 
        android:textStyle="bold" 
        android:layout_height="wrap_content" 
        android:layout_width="wrap_content" 
        android:id="@+id/textView4" 
        android:layout_toLeftOf="@+id/button2" 
        android:layout_centerVertical="true" 
        android:paddingRight="25dip" 
        android:textSize="18dip"> 
      </TextView> 
    </RelativeLayout> 

    <TableLayout android:id="@+id/tableLayout1" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:shrinkColumns="1"> 

     <TableRow android:id="@+id/tableRow1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:divider="@android:color/black" 
      android:dividerPadding="2dip"> 
      <ListView 
        android:id="@+id/listView1" 
        android:layout_height="wrap_content" 
        android:layout_width="0dip" 
        android:layout_weight="1" 
        android:clickable="true" 
        android:focusable="true" 
        > 
      </ListView> 
      <TableLayout android:id="@+id/tableLayout2" 
        android:layout_width="0dip" 
        android:layout_height="wrap_content" 
        android:layout_weight="1" 
        android:shrinkColumns="1"> 
       <TextView 
        android:text="dummy3" 
        android:id="@+id/textView1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textStyle="bold" 
        android:padding="8dip" 
        android:textSize="18dip" 
        android:background="#ff238E23"> 
       </TextView> 
       <ListView 
        android:id="@+id/listView2" 
        android:layout_height="0dip" 
        android:layout_weight="1" 
          android:drawSelectorOnTop="false" 
          android:divider="@android:color/white" 
          android:dividerHeight="2dip" 
        android:layout_width="match_parent" 
          android:clickable="true" 
          android:focusable="true" 
        > 
       </ListView> 
       <TextView 
        android:text="dummy4" 
        android:textSize="18dip" 
        android:textStyle="bold" 
        android:id="@+id/textView2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:background="#ff0000ff" 
        android:padding="8dip"> 
       </TextView> 
       <ListView 
        android:id="@+id/listView3" 
        android:layout_height="0dip" 
        android:layout_weight="1" 
          android:drawSelectorOnTop="false" 
          android:divider="@android:color/white" 
          android:dividerHeight="2dip" 
        android:layout_width="match_parent" 
          android:clickable="true" 
          android:focusable="true" 
        > 
       </ListView> 
      </TableLayout> 
     </TableRow> 

    </TableLayout> 
(AdapterView arg0, 뷰 뷰, int arg2, long arg3) { Log.v ("blah", "arg2"+ arg2); Log.v ("blah", "arg3"+ arg3); } });

나머지 두 목록에 대해 비슷한 작업을 수행합니다. R.id.listView2 및 R.id.listView4. 그들은 다른 어댑터를 인스턴스화하지만 아무 것도 과 크게 다릅니다.

로그가 인쇄되지 않습니다. 항목을 클릭 할 수없고 onClickItem 수신기가 트리거되도록하는 이유는 무엇입니까? 이렇게해도 lv.setFocusable (true); lv.setClickable (true); 도움이되지 않습니다.

어떤 현상이 발생하고 있는지 알 수 있습니까?

감사합니다.

+0

아래 답변을 요청 했어야합니다. 목록보기에 콘텐츠를 채우고 있습니까? 나는 내가 무엇을 묻고 있는지 짐작한다. 당신이 그들을 클릭하려고 할 때 listviews에서 무엇이든 볼 수 있는가? –

답변

1

ListView 요소가 보이지 않거나 높이가 0 일 수 있습니다. ListView가 채워지지 않으면 높이 (wrap_content로 인해)가 0이되어 클릭 할 수 없게됩니다. 테스트로서 수동으로 높이를 25sp로 설정하고 차이가 있는지 확인하십시오.

편집 : 어댑터 내에 onclicklistener를 설정해야합니다. 현재, 어댑터가 채워진 항목에는 전체 목록보기가 아닌 포커스가 있습니다. 예를 들어 this을 참조하십시오.

+0

또 다른 문제는 콘텐츠를 채우는 경우 어댑터로 인스턴스화 된 clicklisteners가 클릭 이벤트를 잡아 전체 목록보기 대신 채워진 항목으로 전달한다는 것입니다. –

+0

나는 listviews를 채우고있다. 화면의 내용을 볼 수 있습니다. 나는 심지어 목록보기를 srcoll 할 수있다.그러나 목록 항목을 클릭하면 강조 표시된 것이 아니며 onClick Listener가 트리거됩니다. –

+0

내 대답을 편집하여 문제가 해결되는지 확인하십시오. –