2010-07-09 4 views
0

Eclipse에서 Android 용 앱을 개발하고 있습니다. 현재 API 레벨 3을 대상으로하고 있지만 Android 1.6 에뮬레이터 (API 레벨 4)에서 실수로 테스트했습니다. 1.6에서는 정상적으로 작동했지만, 1.5에서 ListView는 CHOICE_MODE_SINGLE을 사용하여 클릭 할 때 항목을 선택하지 않습니다.ListView가 Android 1.5의 항목을 확인하지 않습니다.

<ListView 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent" 
    android:layout_weight="1" 
    android:id="@+id/ListDomains" 
    android:layout_margin="5px" 
    android:choiceMode="singleChoice" 
    android:clickable="false" 
    android:focusable="true" 
    android:focusableInTouchMode="true" 
    android:descendantFocusability="beforeDescendants" 
> 
</ListView> 

는 여기에 목록보기의 항목에 대한 XML의 :

여기 내 목록보기 XML의

<?xml version="1.0" encoding="utf-8"?> 
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_height="wrap_content" 
    android:id="@+id/domain_list_value" 
    android:checkMark="?android:attr/listChoiceIndicatorSingle" 
    android:textAppearance="?android:attr/textAppearanceLarge" 
    android:layout_width="fill_parent" 
> 
</CheckedTextView> 

내가 날의 getView을 사용자 정의 할 수 있도록 사용자 정의 ArrayList에 어댑터를 만들었습니다.

public class DomainArrayAdapter extends ArrayAdapter<char[]> { 

    private LayoutInflater mInflater; 

    public DomainArrayAdapter(Context context, int textViewResourceId, 
      List<char[]> objects) {  
     super(context, textViewResourceId, objects);  
     mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     if(convertView == null){ 
      convertView = mInflater.inflate(R.layout.domain_list, null); 
     } 

     char[] text = super.getItem(position); 

     ((CheckedTextView)convertView).setText(text, 0, text.length); 
     return convertView; 
    } 

} 

이 모든 코드의 미세 API 레벨 3에 대해 컴파일 및 안드로이드 1.6 에뮬레이터에서 실행되는 작품 : 여기에 DomainArrayAdapter의 코드입니다. 그러나 1.5 에뮬레이터에 대해 실행하면 ListView의 항목은 클릭 할 때 확인하지 않습니다.

아이디어가 있으십니까?

답변

1

Android 1.5는 listview XML에 설정된 choiceMode를 준수하지 않습니다. 프로그래밍 방식으로 설정하면 올바르게 작동합니다.

ListView listDomains = (ListView) findViewById(R.id.ListDomains); 

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 0 

    listDomains.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 

    Log.d("app", String.valueOf(listDomains.getChoiceMode())); //prints 1 

다른 사람이 이런 종류의 동작을 본 적이 있습니까?

관련 문제