Skip to content

Commit

Permalink
完善子条目点击和长按设置
Browse files Browse the repository at this point in the history
  • Loading branch information
chaychan committed Mar 25, 2018
1 parent 6daf8e2 commit f8f44f1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.chaychan.multiitemrvadapter.R;
import com.chaychan.multiitemrvadapter.adapter.MessageListAdapter;
import com.chaychan.multiitemrvadapter.model.ImageMessage;
import com.chaychan.multiitemrvadapter.model.Message;
import com.chaychan.multiitemrvadapter.R;
import com.chaychan.multiitemrvadapter.model.TextMessage;
import com.chaychan.multiitemrvadapter.adapter.MessageListAdapter;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -37,6 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
mMessages.add(new TextMessage("嗯嗯,今天天气真不错!"));
mMessages.add(new ImageMessage(imgUrl2));

mRvMessages.setAdapter(new MessageListAdapter(mMessages));
MessageListAdapter adapter = new MessageListAdapter(mMessages);
mRvMessages.setAdapter(adapter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,34 @@ protected void convert(BaseViewHolder helper, T item) {
}

private void bindClick(final BaseViewHolder helper, final T item, final int position, final BaseItemProvider provider) {
OnItemClickListener clickListener = getOnItemClickListener();
OnItemLongClickListener longClickListener = getOnItemLongClickListener();

if (clickListener != null && longClickListener != null){
//如果已经设置了子条目点击监听和子条目长按监听
return;
}

View itemView = helper.itemView;

itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
provider.onClick(helper, item, position);
}
});
if (clickListener == null){
//如果没有设置点击监听,则回调给itemProvider
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
provider.onClick(helper, item, position);
}
});
}

itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return provider.onLongClick(helper, item, position);
}
});
if (longClickListener == null){
//如果没有设置长按监听,则回调给itemProvider
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return provider.onLongClick(helper, item, position);
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class ProviderDelegate {
public void registerProvider(BaseItemProvider provider){
ItemProviderTag tag = provider.getClass().getAnnotation(ItemProviderTag.class);
if (tag == null){
throw new RuntimeException("ItemProviderTag not def layout");
throw new RuntimeException("Can not find the annotation: 'ItemProviderTag'");
}

int viewType = tag.viewType();
Expand Down

0 comments on commit f8f44f1

Please sign in to comment.