मैं हमारे समाधान TokenAutoComplete on github मुक्त-स्रोत बना। मेरा परीक्षण 2.2 पर वापस किया गया है। मैंने अपने कोड को बहुत सरल कार्यान्वयन और अनुकूलन की अनुमति देने के लिए डिज़ाइन किया है। मुझे यकीन नहीं है कि यह आपके प्रश्न का काफी उत्तर देता है, लेकिन यह चिप्स स्रोत कोड की तुलना में बेहतर प्रारंभिक बिंदु हो सकता है।
यहाँ मेरी लाइब्रेरी का उपयोग कर एक उदाहरण दिया गया है:
उपवर्ग TokenCompleteTextView contact_token के लिए
public class ContactsCompletionView extends TokenCompleteTextView {
public ContactsCompletionView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View getViewForObject(Object object) {
Person p = (Person)object;
LayoutInflater l = (LayoutInflater)getContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
LinearLayout view = (LinearLayout)l.inflate(R.layout.contact_token, (ViewGroup)ContactsCompletionView.this.getParent(), false);
((TextView)view.findViewById(R.id.name)).setText(p.getEmail());
return view;
}
@Override
protected Object defaultObject(String completionText) {
//Stupid simple example of guessing if we have an email or not
int index = completionText.indexOf('@');
if (index == -1) {
return new Person(completionText, completionText.replace(" ", "") + "@example.com");
} else {
return new Person(completionText.substring(0, index), completionText);
}
}
}
लेआउट कोड (अगर लेआउट के किसी भी प्रकार का उपयोग कर सकते या में एक imageView फेंक अगर आप में छवियों चाहते सकता है टोकन)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/token_background"
android:padding="5dp"
android:textColor="@android:color/white"
android:textSize="18sp" />
</LinearLayout>
टोकन backgound drawable
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#ffafafaf" />
<corners
android:topLeftRadius="5dp"
android:bottomLeftRadius="5dp"
android:topRightRadius="5dp"
android:bottomRightRadius="5dp" />
</shape>
व्यक्ति वस्तु कोड
public class Person implements Serializable {
private String name;
private String email;
public Person(String n, String e) { name = n; email = e; }
public String getName() { return name; }
public String getEmail() { return email; }
@Override
public String toString() { return name; }
}
नमूना गतिविधि
public class TokenActivity extends Activity {
ContactsCompletionView completionView;
Person[] people;
ArrayAdapter<Person> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
people = new Person[]{
new Person("Marshall Weir", "[email protected]"),
new Person("Margaret Smith", "[email protected]"),
new Person("Max Jordan", "[email protected]"),
new Person("Meg Peterson", "[email protected]"),
new Person("Amanda Johnson", "[email protected]"),
new Person("Terry Anderson", "[email protected]")
};
adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_list_item_1, people);
completionView = (ContactsCompletionView)findViewById(R.id.searchView);
completionView.setAdapter(adapter);
completionView.setPrefix("To: ");
}
}
लेआउट कोड
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.tokenautocomplete.ContactsCompletionView
android:id="@+id/searchView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</RelativeLayout>
'chip' के लिए एक अलग शब्द को खोजने के लिए प्रयास करें। मुझे नहीं पता कि एक चिप क्या है, "फ्रेंच फ्राई" या आलू कुरकुरा के लिए अमेरिकी नाम के उचित नाम के अलावा। – Simon
पृष्ठभूमि में स्पैन करने योग्य स्ट्रिंग की पृष्ठभूमि छवि चिप के रूप में कहा जाता है। किसी भी तरह से मैंने चिप पाठ को बबल में बदल दिया। मुझे लगता है कि अधिकांश एंड्रॉइड डेवलपर्स बहुआयामी टेक्स्टव्यू के साथ चिप या बबल के बारे में जानेंगे। अगर कोई विचार है तो कृपया मुझे समाधान के बारे में बताएं .. @ साइमन – AndroidDev