내 목록보기의 내용을 검색 할 때 잘못된 항목이 표시되는 것으로 보이는 사용자 정의 목록보기에 문제가 있습니다.체크 표시가 잘못된 항목을 표시했습니다 (simpleCursor + 사용자 정의 레이아웃 사용)
는 이름 AA로 검색하여
나는 나에 검색 한 두 행 (AABBCCC 및 AABC)를 선택했지만 선택하지 않은 (당신이 이해 아래 스크린 샷을 확인) 행 (Jana와 Nathan). 그러나 그것은 선택된 것으로 보여지고 있습니다.
검색 항목이 모두 제거되었으며 검색을 제거한 후에 행을 선택하지 않았습니다. 그것은 두 개의 행 (AABBCC와 AABC)을 보여 주기로되어 있지만 잘못된 행 Jana를 보여주고 있습니다.
나는 위의 동작을 재정의하지 않는 방법에 대해 설명합니다. 위치가 아니라 _rowid를 기반으로 확인 가능한 연락처로 연락해야합니다.
목록에서 선택한 항목을 추적 할 클래스는 무엇입니까? 위의 동작을 재정의하는 방법 ??
두 행의 이름과 번호가 있습니다. 나는 checkable을 구현하는 내 레이아웃 (아래 코드)을 사용자 정의했습니다. 체크 할 항목
Search Name(EditText) [Done Btn]
---------------------------------------
Contact_name_1
Phone_no
---------------------------------------
Contact_name_2
Phone_no2
---------------------------------------
Contact_name_3
Phone_no3
---------------------------------------
사용자 정의 레이아웃 ..
public class CustomCheckableLists extends RelativeLayout implements Checkable {
private Checkable mCheckable;
public CustomCheckableLists(Context context) {
super(context);
}
public CustomCheckableLists(Context context, AttributeSet attrs)
{
super(context,attrs);
}
public boolean isChecked() {
return mCheckable == null ? false : mCheckable.isChecked();
//return false;
}
public void setChecked(boolean checked) {
if(mCheckable != null)
mCheckable.setChecked(checked);
}
public void toggle() {
if(mCheckable != null)
mCheckable.toggle();
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
//Find items id..
Log.w("onFinishInflate","onFinishInflate");
// Find Checkable child
int childCount = getChildCount();
for (int i = 0; i < childCount; ++i) {
View v = getChildAt(i);
if (v instanceof Checkable) {
mCheckable = (Checkable) v;
break;
}
}
}
사용자 정의 XML 레이아웃
<CustomCheckableLists
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical"
android:orientation="horizontal"
>
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:visibility="invisible"
/>
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="nuoo"
/>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/phonenu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/textCheckMark"
android:gravity="center_vertical"
android:paddingLeft="3dp"
android:paddingRight="6dp"
android:paddingTop="25dip"
/>
</CustomCheckableLists>
연락 활동 클래스
String[] columns = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
int[] to = new int[] {
R.id.id,
R.id.text1,
R.id.phonenu
};
dataAdapter = new SimpleCursorAdapter(this, R.layout.custom_checkable_item, cursor, columns, to);
listView.setAdapter(dataAdapter);
도움을 주시면 감사하겠습니다. 미리 감사드립니다.
사용자 검색이 어떤 이름에 대한 쿼리가 검색 결과를 반환하기 위해 형성 될 때마다 편집
.
searchNameOrNumber = (EditText) findViewById(R.id.searchText);
searchNameOrNumber.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence searchterm, int start, int before, int count) {
Log.w("Text Searched.. ", " " + searchterm);
dataAdapter.getFilter().filter(searchterm.toString());
//dataAdapter.notifyDataSetChanged();
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void afterTextChanged(Editable s) {
}
});
dataAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
Log.w("Searched Query..,", constraint.toString());
);
return getSearchedContacts(constraint.toString());
}
});
public Cursor getSearchedContacts(String inputText)
{
Log.w("inputText",inputText);
Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone.NUMBER
};
String selection = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " like '%" + inputText + "%'";
Cursor people = getContentResolver().query(uri, projection, selection, null, null);
int indexName = people.getColumnIndex(StructuredName.DISPLAY_NAME);
int indexNumber = people.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER);
int idIdx = people.getColumnIndexOrThrow(PhoneLookup._ID);
if(!people.moveToFirst())
{
Log.w("No Cursor.., ","No cursor.., Cursor is empty..");
}
do {
String id = people.getString(idIdx);
String name = people.getString(indexName);
String number = people.getString(indexNumber);
// Do work...
} while (people.moveToNext());
return people;
}
@dmom 감사합니다. – swastican