Update android dropdown MultiAutoCompleteTextView

I want to implement user tagging functionality in android app. I want the same functionality as Facebook with user tags in comments. For this, I applied Custom MultiAutoCompleteTextView

in my application and I also wanted to display both the user image and the username. For this I have implemented a custom one SimpleAdapter

with a custom one Filter

for the MultiAutoCompleteTextView. I have referenced this link and achieved this functionality.

The change I want to implement is that whenever I select any item from the dropdown, that item should be removed from the dropdown and the dropdown data should be updated with the rest of the data. And if I remove this selected item explicitly from the AutocompleteText, then this erased item should reappear in the select box. I don't know how to achieve this. I searched a lot but could find the right solution. Please help me to solve this problem.

Thank.

Operation code:

    edtCommentTag.setTokenizer(new Tokenizer() {

            @Override
            public CharSequence terminateToken(CharSequence text) {
                int i = text.length();
                while (i > 0 && text.charAt(i - 1) == ' ')
                    i--;
                if (i > 0 && text.charAt(i - 1) == ' ') {
                    return text;
                } else {
                    if (text instanceof Spanned) {
                        SpannableString sp = new SpannableString(text + " ");
                        TextUtils.copySpansFrom((Spanned) text, 0,
                                text.length(), Object.class, sp, 0);
                        return sp;
                    } else {
                        return text + " ";
                    }

                }
            }

            @Override
            public int findTokenStart(CharSequence text, int cursor) {

                int i = cursor;
                while (i > 0 && text.charAt(i - 1) != '@')
                    i--;
                if (i < 1 || text.charAt(i - 1) != '@')
                    return cursor;
                return i;
            }

            @Override
            public int findTokenEnd(CharSequence text, int cursor) {
                int i = cursor;
                int len = text.length();
                while (i < len) {
                    if (text.charAt(i) == ' ')
                        return i;
                    else
                        i++;
                }
                return len;

            }
        });

        adpReply = new CommentAdapter(CommentActivity.this,
                            finalResult, R.layout.liker_comment_row, from, to);

        edtCommentTag.setAdapter(adpReply);

      

Comment Adapter Code:

public class CommentReplyAdapter extends SimpleAdapter {

    private List<HashMap<String, String>> lstFollowing, suggestions,
            tempLstFollowing;
    RoundedImageView imgUser;
    TextView txtUname;
    private LayoutInflater mInflater;
    Context context;
    private ImageLoader imgLoader;
    private DisplayImageOptions options;
    private Filter nameFilter;

    public CommentReplyAdapter(Context context,
            List<HashMap<String, String>> lstFollowing, int lytId,
            String[] from, int[] to) {

        super(context, lstFollowing, lytId, from, to);

        this.context = context;
        this.lstFollowing = lstFollowing;
        this.tempLstFollowing = new ArrayList<HashMap<String, String>>();
        this.tempLstFollowing.addAll(lstFollowing);
        this.suggestions = new ArrayList<HashMap<String, String>>();

        this.mInflater = LayoutInflater.from(context);
        imgLoader = ImageLoader.getInstance();
        imgLoader.init(ImageLoaderConfiguration.createDefault(this.context));
        options = new DisplayImageOptions.Builder()
                .showImageOnLoading(R.drawable.loading_img)
                .showImageForEmptyUri(R.drawable.ic_launcher)
                .showImageOnFail(R.drawable.loading_img).cacheInMemory(true)
                .cacheOnDisc(true).considerExifParams(true)
                .bitmapConfig(Bitmap.Config.RGB_565)
                .resetViewBeforeLoading(true).build();

    }

    @SuppressWarnings("unchecked")
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        try {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.liker_comment_row,
                        null);
            }
            txtUname = (TextView) convertView
                    .findViewById(R.id.txtUserName_likeComment);
            imgUser = (RoundedImageView) convertView
                    .findViewById(R.id.userImage_likeComment);
            HashMap<String, String> data = (HashMap<String, String>) getItem(position);

            txtUname.setText(data.get("uname"));
            imgLoader.displayImage(data.get("avtar"), imgUser, options);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return convertView;

    }
@Override
    public Filter getFilter() {
        setUpFilter();
        return nameFilter;

    }

    private void setUpFilter() {

        try {

            nameFilter = new Filter() {

                @SuppressWarnings("unchecked")
                @Override
                public CharSequence convertResultToString(Object resultValue) {

                    String str = ((HashMap<String, String>) resultValue)
                            .get("uname");
                    return str;
                }

                @Override
                protected FilterResults performFiltering(CharSequence constraint) {
                    if (constraint != null) {
                        String newConstraint = constraint.toString();
                        Log.e("newConstraint -- outer", newConstraint);

                        suggestions.clear();
                        for (HashMap<String, String> hm : tempLstFollowing) {
                            String uname = hm.get("uname").toString()
                                    .toLowerCase(Locale.ENGLISH);
                            if (uname.startsWith(newConstraint.toString()
                                    .toLowerCase(Locale.ENGLISH))) {
                                suggestions.add(hm);
                                // hasFound = true;
                            }
                        }

                        FilterResults filterResult = new FilterResults();
                        filterResult.values = suggestions;
                        filterResult.count = suggestions.size();
                        return filterResult;

                    } else {
                        return new FilterResults();
                    }

                }

                @SuppressWarnings("unchecked")
                @Override
                protected void publishResults(CharSequence constraint,
                        FilterResults results) {

                    if (results != null && results.count > 0) {

                        lstFollowing = (List<HashMap<String, String>>) results.values;

                        notifyDataSetChanged();
                    } else {

                        lstFollowing.clear();
                        lstFollowing.addAll(tempLstFollowing);
                    }

                }

            };

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

      

+3
android android-filterable autocompletetextview multiautocompletetextview


source to share


No one has answered this question yet

See similar questions:

29
Android: Autocomplete TextView is similar to Facebook app

or similar:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
1296
Reloading activity on android rotation
0
Saving the state of a ToggleButton to a ListView using SharedPreferences



All Articles
Loading...
X
Show
Funny
Dev
Pics