मैं कस्टम CustomerAdapter हैएंड्रॉयड AutoCompleteTextView कस्टम एडाप्टर छानने काम नहीं कर रहा
public class CustomerAdapter extends ArrayAdapter<Customer> {
private final String MY_DEBUG_TAG = "CustomerAdapter";
private ArrayList<Customer> items;
private int viewResourceId;
public CustomerAdapter(Context context, int viewResourceId, ArrayList<Customer> items) {
super(context, viewResourceId, items);
this.items = items;
this.viewResourceId = viewResourceId;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(viewResourceId, null);
}
Customer customer = items.get(position);
if (customer != null) {
TextView customerNameLabel = (TextView) v.findViewById(R.id.customerNameLabel);
if (customerNameLabel != null) {
customerNameLabel.setText(String.valueOf(customer.getName()));
}
}
return v;
}
}
और customer_auto
लेआउट
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customerNameLabel"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:padding="10dp" android:textSize="16sp"
android:textColor="#000">
</TextView>
और पर अपने public void onCreate
AutoCompleteTextView customerAutoComplete = (AutoCompleteTextView) findViewById(R.id.autocomplete_customer);
CustomerAdapter customerAdapter = new CustomerAdapter(this, R.layout.customer_auto, customerList);
customerAutoComplete.setAdapter(customerAdapter);
और Customer.java
public class Customer implements Parcelable {
private int id;
private String name = "";
public Customer() {
// TODO Auto-generated constructor stub
}
/**
* This will be used only by the MyCreator
*
* @param source
*/
public Customer(Parcel source) {
/*
* Reconstruct from the Parcel
*/
id = source.readInt();
name = source.readString();
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return this.id;
}
public String getName() {
return this.name;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(id);
dest.writeString(name);
}
public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
@Override
public Customer createFromParcel(Parcel source) {
return new Customer(source);
}
@Override
public Customer[] newArray(int size) {
return new Customer[size];
// TODO Auto-generated method stub
}
};
@Override
public String toString() {
return this.name;
}
}
लेकिन ऑटो सुझाव बॉक्स सही ढंग से फ़िल्टर नहीं करता है। उदाहरण के लिए; अगर मैं an
टाइप करता हूं तो परीक्षण बॉक्स में br
से शुरू होने वाले ग्राहक दिखा रहे हैं!
मुझे लगता है कि आपको उस ग्राहक की जांच करने की आवश्यकता है जिसे आप ग्राहक एडाप्टर में भेज रहे हैं। इसमें गलत डेटा हो सकता है। आप कहां से उस सूची को बना रहे हैं? – kosa
नहीं, 'ग्राहक सूची' में सही डेटा है, जब मैंने इसे 'स्पिनर' में उपयोग किया तो यह सही ढंग से दिखाया गया –
क्या आपने सुझाव बॉक्स में प्रदर्शित करने से पहले उन्हें प्रिंट किया था?setText से ठीक पहले? जो कुछ सुराग दे सकता है। साथ ही मैं ऐप को अनइंस्टॉल करने और पुनः इंस्टॉल करने का सुझाव दूंगा। – kosa