danylovolokh / HashTagHelper

This is a library designed for highlighting hashtags ("#example") and catching click on them.
592 stars 71 forks source link

onHashTagClicked not working correctly #8

Closed Shajeel-Afzal closed 8 years ago

Shajeel-Afzal commented 8 years ago

I am showing Hash Tags in a TextView in the RecyclerAdaper.

Problem is that the Click Listener on the adapter Item is not working properly when i am using HashTagHelper library. If the user clicks on TextView's text that is not a Hash Tag then the onClick of the Item is not being called.

Inside onBindView method i am showing the Hash Tag on the TextView:

@Override
    public void onBindViewHolder(TaskViewHolder holder, int position) {
        ...
        holder.mTaskTitleTv.setText(mTasksList.get(position).getTitle());
        holder.mTextHashTagHelper.handle(holder.mTaskTitleTv);
    }

And ViewHolder looks like this:

class TaskViewHolder extends RecyclerView.ViewHolder implements OnClickListener {

        ...
        public TaskViewHolder(View itemView) {
            super(itemView);
            findViews(itemView);
            itemView.setOnClickListener(this);
            mTextHashTagHelper = HashTagHelper.Creator.create(mContext.getResources().getColor(R.color.primary), new HashTagHelper.OnHashTagClickListener() {
                @Override
                public void onHashTagClicked(String hashTag) {
                    mContext.startActivity(HashTagTaskActivity.createLauncherIntent(mContext, hashTag));
                }
            });
        }

       @Override
        public void onClick(View v) {
            mListner.onItemClick(v, getLayoutPosition());
        }
}
danylovolokh commented 8 years ago

As you said: If the user clicks on TextView's text that is not a Hash Tag then the onClick of the Item is not being called.

The HashTagHelper is designed to handle clicks on hashtags only. It doesn't call onClick on a regular text without #hashtag.

The library is opensource. Feel free to modify it to suit your needs

Shajeel-Afzal commented 8 years ago

Alright. I will try to understand the code and do the changes to achieve what i need. Thanks.