custom autocomplete

A

assenda

Ambitioniertes Mitglied
0
Hallo alle zusammen :winki:
Ich hab ein gutes Tutorial zum Thema Custom autoComplete gefunden...erstmal wollte ich es euch nicht vorenthalten, zum anderen wollte ich Äderungen vornehmen und brauche dabei eure Hilfe :huh:



Jetzt stehe ich vor dem Problem, dass, sobald ich aus dem Dropdownfeld eine auswahl treffe folgendes in das Autocompletefeld geschrieben wird:

213020009327.jpg


{Name=Vorname Nachname, Type=Mobile, Phone=017-700-000}

--> Also wird nur der Eintrag aus der Map ausgelesen und in das Feld geschrieben.

Ich will jedoch, dass NUR der Name in das Feld geschrieben wird!
Also so, wie Android das beim einfügen eines Empfängers bei den Sms macht!


Weiß jemand wie ich da vorgehen muss??????!

Hier das Funtionierende Projekt als Download:
http://uploaded.to/file/pw9i7gm8

Vorab: in der AndroidManifest.xml muss die permission gesetzt sein:

Code:
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
Start.java

Code:
package test.test;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.AutoCompleteTextView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

public class Start extends Activity {

    private ArrayList<Map<String, String>> mPeopleList;

    private SimpleAdapter mAdapter;
    private AutoCompleteTextView mTxtPhoneNo;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mPeopleList = new ArrayList<Map<String, String>>();
        
        mTxtPhoneNo = (AutoCompleteTextView) findViewById(R.id.mmWhoNo);
        PopulatePeopleList();
        
        mAdapter = new SimpleAdapter(this, mPeopleList, R.layout.custcontview, new String[] { "Name", "Phone", "Type" }, new int[] { R.id.ccontName, R.id.ccontNo, R.id.ccontType });
        mTxtPhoneNo.setAdapter(mAdapter);
    }

    public void PopulatePeopleList() {

        mPeopleList.clear();

        Cursor people = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);

        while (people.moveToNext()) {
            
            String contactName = people.getString(people.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
            String contactId = people.getString(people.getColumnIndex(ContactsContract.Contacts._ID));
            String hasPhone = people.getString(people.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));

            if ((Integer.parseInt(hasPhone) > 0)) {

                Cursor phones = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
                while (phones.moveToNext()) {

                    String phoneNumber = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                    String numberType = phones.getString(phones.getColumnIndex(ContactsContract.CommonDataKinds.Phone.TYPE));

                    Map<String, String> NamePhoneType = new HashMap<String, String>();

                    NamePhoneType.put("Name", contactName);
                    NamePhoneType.put("Phone", phoneNumber);

                    if (numberType.equals("0"))
                        NamePhoneType.put("Type", "Work");
                    else if (numberType.equals("1"))
                        NamePhoneType.put("Type", "Home");
                    else if (numberType.equals("2"))
                        NamePhoneType.put("Type", "Mobile");
                    else
                        NamePhoneType.put("Type", "Other");
                    
                    mPeopleList.add(NamePhoneType);
                }
                phones.close();
            }
        }
        people.close();

        startManagingCursor(people);
    }
}
main.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <AutoCompleteTextView android:id="@+id/mmWhoNo" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:hint="To....">
    </AutoCompleteTextView>
</LinearLayout>
customview.xml

Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:id="@+id/ccontName" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>
    <TextView android:id="@+id/ccontType" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>
    <TextView android:id="@+id/ccontNo" android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>
</LinearLayout>
Viel Spaß beim umsetzen
und würde mich freuen, wenn ihr eure Ideen zu dem genannten Problem schildert :winki:
 
Zuletzt bearbeitet:

Ähnliche Themen

J
Antworten
2
Aufrufe
985
justinh13
J
J
Antworten
2
Aufrufe
692
JoEntwickler
J
Zurück
Oben Unten