2012-06-12 3 views
0

검색 결과가 Activity인데 그 레이아웃 파일은 다음과 같습니다. 위에ListView에 대한 포커스 문제

<?xml version="1.0" encoding="utf-8"?> 
       <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="vertical" > 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/white2" > 

        <EditText 
         android:id="@+id/et_search" 
         android:layout_width="280dp" 
         android:layout_height="wrap_content" 
         android:layout_gravity="center" 
         android:layout_marginBottom="5dp" 
         android:layout_marginLeft="20dp" 
         android:layout_marginRight="20dp" 
         android:layout_marginTop="5dp" 
         android:drawableRight="@drawable/search_20" 
         android:ems="10" 
         android:hint="Search by name" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:background="@color/grey05" 
        android:orientation="horizontal" > 

        <TextView 
         android:id="@+id/tv_name" 
         android:layout_width="1dip" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_weight="0.25" 
         android:text="Name" 
         android:textAppearance="?android:attr/textAppearanceMedium" > 
        </TextView> 

        <TextView 
         android:id="@+id/tv_sno" 
         android:layout_width="1dip" 
         android:layout_height="wrap_content" 
         android:layout_weight="0.25" 
         android:text="Serial No." 
         android:textAppearance="?android:attr/textAppearanceMedium" > 
        </TextView> 

        <TextView 
         android:id="@+id/tv_type" 
         android:layout_width="1dip" 
         android:layout_height="wrap_content" 
         android:layout_marginLeft="20dp" 
         android:layout_weight="0.25" 
         android:text="Type" 
         android:textAppearance="?android:attr/textAppearanceMedium" > 
        </TextView> 
       </LinearLayout> 

       <ListView 
        android:id="@+id/listView1" 
        android:layout_width="match_parent" 
        android:layout_height="0dip" 
        android:layout_weight="1" 
        android:transcriptMode="normal" > 
       </ListView> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="2dp" 
        android:layout_marginRight="2dp" 
        android:orientation="horizontal" > 

        <Button 
         android:id="@+id/btn_chkin" 
         android:layout_width="0dip" 
         android:layout_height="50dip" 
         android:layout_marginBottom="5dip" 
         android:layout_marginRight="2dip" 
         android:layout_marginTop="20dip" 
         android:layout_weight="1" 
         android:background="@drawable/custombutton" 
         android:text="Submit" /> 

        <Button 
         android:id="@+id/btn_chkout" 
         android:layout_width="0dip" 
         android:layout_height="50dip" 
         android:layout_marginBottom="5dip" 
         android:layout_marginLeft="2dip" 
         android:layout_marginTop="20dip" 
         android:layout_weight="1" 
         android:background="@drawable/custombutton" 
         android:text="Cancel" /> 
       </LinearLayout> 

      </LinearLayout> 

검색 EditText, 중심과 화면의 하단에 두 개의 버튼의 목록보기.

하나의 항목을 Listview에 집중시킬 수 없습니다. 목록보기 어댑터의 레이아웃 파일에서 가 나는 항목을 선택하면 여전히 선택한 항목이 강조 표시되지 않습니다 android:clickable="false" android:focusable="false" .. 나는 또한 onItemClick

에 다음 코드를 넣어 시도 을 설정 한 절대적으로 에뮬레이터에 잘하지만, 내 삼성 갤럭시 Y에 # 1 작품
// @Override 
    public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
      long id) { 

     if (lview3 != null) { 
      lview3.getChildAt(prevPos).setBackgroundColor(Color.BLACK);   
      lview3.getChildAt(position).setBackgroundColor(Color.BLUE); 
     } 
     prevPos = position; 
    } 
// @Override 
public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
     long id) { 
     lview3.setSelection(position); 
} 

, 그것은 * "어플리는 말한다 양이온이 예기치 않게 멈췄습니다. 다시 시도하십시오. "*

# 2의 경우 손가락을 떼면 항목이 강조 표시되고 강조 표시 색은 사라집니다.

내 listview_row.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/linLayout_search" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/tv_name" 
     android:layout_width="1dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.25"   
     android:text="Medium Text" 
     android:textSize="15sp" /> 

    <TextView 
     android:id="@+id/tv_sno" 
     android:layout_width="1dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.25"  
     android:text="Medium Text" 
     android:textSize="15sp" /> 

    <TextView 
     android:id="@+id/tv_type" 
     android:layout_width="1dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.30"   
     android:text="Medium Text" 
     android:textSize="15sp" /> 

</LinearLayout> 
+0

android : clickable = "false"android : focusable = "false"이 속성을 true로 설정하십시오. – Akram

+0

오류 로그 게시 –

+0

에뮬레이터에서 ur 앱을 확인하지 마십시오. 모든 Android 휴대 전화로 확인하면 모든 버그를 잡을 수 있습니다. – anoop

답변

0

Yipeee ... https://stackoverflow.com/a/10277370/840520 이 문제를 해결했다. 여기에 내 ListAdapter

// set selected item 
    LinearLayout activeItem = (LinearLayout) convertView; 

    if (position == SearchAssetActivity.selectedItem){ 
     activeItem.setBackgroundColor(Color.GRAY); 
     // for focus on it 
     int top = (activeItem == null) ? 0 : activeItem.getTop(); 
     ((ListView) parent).setSelectionFromTop(position, top); 
    } 
    else{ 
     activeItem.setBackgroundColor(Color.BLACK); 
    } 
2

당신은

// inside onCreate method 
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    // Make the newly clicked item the currently selected one. 
    getListView().setItemChecked(position, true); 
} 

이 전에 .This 목록보기에들이 지속적인 선택을위한 표준 코드 목록보기에서 선택 모드를 가지고 당신이의 getView() 필요 added..in 무엇 선택기

android:background="@drawable/activated_background" 

activated_background.xml

,369로 목록보기 항목의 레이아웃 배경 설정
<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" android:exitFadeDuration="400"> 

    <item android:drawable="#ff0099cc" android:state_selected="true"/> 
    <item android:drawable="#ff0099cc" android:state_checked="true"/> 
    <item android:drawable="#ff0099cc" android:state_activated="true"/> 
    <item android:drawable="@android:color/transparent"/> 

</selector>