Closed azelas closed 10 months ago
I'm still struggling to understand point 5:
I'm stuck here, when I click the dropdown list of hashtags. When I click on a hashtag, it doesn't load the hashtag name I set but rather my model name and it searches that model name.
Can you explain what your model is? Your custom model should override toString
method. If you can see in SocialArrayAdapter#convertToString
, any hashtagable or mentionable object would be converted to string and that string should pop out in your TextView.
Hi. Thanks for getting back to me.
Some changes that I've made..I put the server request in my performing filter. The issue that I'm having now is that list is shown and disappears very quickly. I don't know what I'm doing wrong. I've debugged it and after showing in getView , the program goes to getCount(), shows the list and after getCount the list disappears.
`
public class HashtagAdapter extends SocialArrayAdapter
private List<TagModel> list;
REST rest;
Context context;
public HashtagAdapter(@NonNull Context context) {
super(context, R.layout.layout_tag, R.id.tag_name);
rest = new REST(context);
this.context = context;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.layout_tag, parent, false);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
TagModel item = list.get(position);
if (item != null) holder.textView.setText(item.getTag_name());
return convertView;
}
@Override
public long getItemId(int position) {
return position;
}
@Nullable
@Override
public TagModel getItem(int position) {
return list.get(position);
}
@Override
public int getCount() {
return list.size();
}
@NonNull
@Override
public Filter getFilter() {
return hashTagFilter;
}
private static class ViewHolder {
final TextView textView;
ViewHolder(@NonNull View view) {
this.textView = view.findViewById(R.id.tag_name);
}
}
private final Filter hashTagFilter = new Filter() {
@Override
protected FilterResults performFiltering(CharSequence constraint) {
FilterResults results = new FilterResults();
if (TextUtils.isEmpty(constraint)) {
return results;
}
final List<TagModel> serverItems = findtagsNow(constraint.toString().substring(1));
results.values = serverItems;
results.count = serverItems.size();
return results;
}
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
if (results != null && results.count > 0) {
list = (List<TagModel>) results.values;
notifyDataSetChanged();
} else {
notifyDataSetInvalidated();
}
}
@Override
public CharSequence convertResultToString(Object resultValue) {
return ((TagModel) resultValue).getTag_name();
}
};
private List<TagModel> findtagsNow(String userinput) {
Map<String, String> params = new HashMap<>();
params.put("table", "get_hashtags");
params.put("value1", userinput);
return rest.tag_list(params);
}
} `
Sorry for late reply. If the dropdownlist disappears without you interacting it, then it suggests a misbehavior of the adapter. From the code you share, I'd say maybe don't implement your own filtering logic as SocialArrayAdapter
already has them. See HashtagArrayAdapter
for example.
Closed for inactivity.
Hello, First of all thanks for this library! I've pretty much set everything up correctly.
I used SocialAutoCompleteTextView - Done
I wanted to use my own REST Api to populate the hashtag list - Done
I made my own adapter that extends ArrayAdapter. The SocialArrayAdapter was filtering the list before the list was made.
I used text.setHashtagTextChangedListener . I didn't really need a filter because as I type something, my app searches.
I'm stuck here, when I click the dropdown list of hashtags. When I click on a hashtag, it doesn't load the hashtag name I set but rather my model name and it searches that model name.
What I'm looking for....Type and have suggestions of hashtags. Click on hashtag in suggestions list and continue typing other non-hashtag words for ex. John #loves playing #tennis. I don't know what I'm missing, do I need something from the SocialArrayAdapter I missed? `