hanggrian / socialview

Android TextView and EditText with hashtag, mention, and hyperlink support
http://hanggrian.com/socialview/
Apache License 2.0
323 stars 81 forks source link

How to apply custom adapter? #36

Closed sbqsbqsbq closed 3 years ago

sbqsbqsbq commented 6 years ago

Hi hendraanggrian, I'm using your library to make mentions like Facebook or Instagram. I've faced problem that I cannot apply my own custom adapter with custom model class. When I apply my custom adapter class, It doesn't show any items.

The Below is my custom adapter code.

` public class PhotoPersonAdaper extends SocialAdapter {

private Context context;
private ArrayList<UserModel> commentTable;

public PhotoPersonAdaper(Context context, int resource, int textViewResourceId, ArrayList<UserModel> commentTable) {
    super(context, resource, textViewResourceId);
    this.context = context;
    this.commentTable = commentTable;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View view = LayoutInflater.from(context).inflate(R.layout.comment_item, null, false);
    CircleImageView image_comment_mention = (CircleImageView) view.findViewById(R.id.image_comment_mention);
    TextView tv = (TextView) view.findViewById(R.id.tv_comment_username);

    Glide.with(context)
            .load(commentTable.get(position).getProfileUrl())
            .into(image_comment_mention);

    tv.setText(commentTable.get(position).getDogName());
    return view;
}

@NotNull
@Override
public String convertToString(UserModel photoCommentTable) {
    return photoCommentTable.getDogName();
}

}`

hanggrian commented 6 years ago

Hi there, sorry for late reply.

Since AutoCompleteTextView uses ArrayAdapter (same one used in ListView), you must familiarize yourself with view holder pattern. See MentionAdapter or HashtagAdapter for example. Post me back if you still have difficulties.

hanggrian commented 3 years ago

Closed due to inactivity.