已实现,具体做法是在adapter中定义一个实现了View.OnClickListener类,通过构造方法传递对应的参数或者位置之类的信息,然后重写onClick方法,在adapter的getView中去找到对应的view去绑定OnClickListener事件即可,代码如下:
public class AiErrorQuestionCollectAdapter extends BaseCommonAdapter<TRAIContactBook>{
private FragmentManager fManager;
public AiErrorQuestionCollectAdapter(Context context, List<TRAIContactBook> list,FragmentManager fManager) {
super(context, list);
this.fManager = fManager;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder(mContext, parent, R.layout.item_list_ai_error_question_collect, position);
holder.setText(R.id.pTime,DateUtils.formatDate(mDatas.get(position).getUpdateTime()));
holder.setText(R.id.rName,mDatas.get(position).getContactBookName());
holder.setText(R.id.df,mDatas.get(position).getDifficultyName());
holder.setText(R.id.grade,mDatas.get(position).getGradeName());
holder.setText(R.id.course,mDatas.get(position).getCourseName());
holder.setText(R.id.isPrint,mDatas.get(position).getPrintStatusName());
holder.setText(R.id.status,mDatas.get(position).getStatusName());
View qBtn = holder.getView(R.id.qBtn);
qBtn.setOnClickListener(new myOnClickListener(mDatas.get(position),"0001"));
View aBtn = holder.getView(R.id.aBtn);
aBtn.setOnClickListener(new myOnClickListener(mDatas.get(position),"0002"));
return holder.getConvertView();
}
class myOnClickListener implements View.OnClickListener {
private TRAIContactBook itemData;
private String type;
public myOnClickListener(TRAIContactBook info,String type) {
this.itemData = info;
this.type = type;
}
@Override
public void onClick(View view) {
LogUtils.e("=1=","onItemClick id:" + itemData.getId());
LogUtils.e("=1=","onItemClick fileUrl:" + itemData.getQuestionPdfUrl());
LogUtils.e("=1=","onItemClick fileUrl:" + itemData.getAnswerPdfUrl());
FragmentTransaction fTransaction = fManager.beginTransaction();
Bundle bd = new Bundle();
if("0001".equals(type)) {
AiErrorQuestionCollectQpdfFragment aiErrorQuestionCollectQpdfFragment = new AiErrorQuestionCollectQpdfFragment(fManager);
bd.putString("id", itemData.getId());
bd.putString("fileUrl",itemData.getQuestionPdfUrl());
LogUtils.e("=1=","onItemClick id:" + bd.get("id"));
LogUtils.e("=1=","onItemClick fileUrl:" + bd.get("fileUrl"));
aiErrorQuestionCollectQpdfFragment.setArguments(bd);
fTransaction.setCustomAnimations(R.anim.fragment_slide_left_enter, R.anim.fragment_slide_left_exit);
fTransaction.replace(R.id.centerFragment, aiErrorQuestionCollectQpdfFragment);
} else if("0002".equals(type)) {
AiErrorQuestionCollectApdfFragment aiErrorQuestionCollectApdfFragment = new AiErrorQuestionCollectApdfFragment(fManager);
bd.putString("id", itemData.getId());
bd.putString("fileUrl",itemData.getAnswerPdfUrl());
LogUtils.e("=1=","onItemClick id:" + bd.get("id"));
LogUtils.e("=1=","onItemClick fileUrl:" + bd.get("fileUrl"));
aiErrorQuestionCollectApdfFragment.setArguments(bd);
fTransaction.replace(R.id.centerFragment, aiErrorQuestionCollectApdfFragment);
} else if("0003".equals(type)) {
}
//加上Fragment替换动画
fTransaction.setCustomAnimations(R.anim.fragment_slide_left_enter, R.anim.fragment_slide_left_exit);
//调用addToBackStack将Fragment添加到栈中
fTransaction.addToBackStack(null);
fTransaction.commit();
}
}
}