Skip to content

Commit

Permalink
git
Browse files Browse the repository at this point in the history
  • Loading branch information
xueliang1 committed Mar 21, 2018
1 parent 989b684 commit 8d8b624
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
Expand Down Expand Up @@ -64,7 +68,8 @@ protected void onCreate(Bundle savedInstanceState) {
int width = getResources().getDisplayMetrics().widthPixels;
final int itemWidth = (int) (width - getResources().getDimension(R.dimen.dp_50));

sectionRecyclerView.setAdapter(new BaseSectionAdapter<ImageInfo, BaseViewHolder>(R.layout.item_image, list) {
BaseSectionAdapter adapter = null;
sectionRecyclerView.setAdapter(adapter = new BaseSectionAdapter<ImageInfo, BaseViewHolder>(R.layout.item_image, list) {


@Override
Expand Down Expand Up @@ -95,5 +100,11 @@ protected void convert(BaseViewHolder helper, ImageInfo item) {
});


adapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i("test","positon="+position);
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ protected K createBaseViewHolder(View view) {
} else {
k = createGenericKInstance(z, view);
}

return k != null ? k : (K) new BaseViewHolder(view);
}

Expand Down Expand Up @@ -116,6 +117,7 @@ public K onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(itemlayout,null);
K k = createBaseViewHolder(view);
k.setAdapter(this);
bindViewClickListener(k);
return k;
}

Expand All @@ -136,19 +138,45 @@ public SupperSection getItem(int position){
}


public AdapterView.OnItemClickListener getmOnItemClickListener() {
public AdapterView.OnItemClickListener getOnItemClickListener() {
return mOnItemClickListener;
}

public void setmOnItemClickListener(AdapterView.OnItemClickListener mOnItemClickListener) {
public void setOnItemClickListener(AdapterView.OnItemClickListener mOnItemClickListener) {
this.mOnItemClickListener = mOnItemClickListener;
}

public AdapterView.OnItemLongClickListener getmOnItemLongClickListener() {
public AdapterView.OnItemLongClickListener getOnItemLongClickListener() {
return mOnItemLongClickListener;
}

public void setmOnItemLongClickListener(AdapterView.OnItemLongClickListener mOnItemLongClickListener) {
public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener mOnItemLongClickListener) {
this.mOnItemLongClickListener = mOnItemLongClickListener;
}

private void bindViewClickListener(final BaseViewHolder baseViewHolder) {
if (baseViewHolder == null) {
return;
}
final View view = baseViewHolder.itemView;
if (view == null) {
return;
}
if (getOnItemClickListener() != null) {
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getOnItemClickListener().onItemClick(null, v, baseViewHolder.getLayoutPosition(),v.getId());
}
});
}
if (getOnItemLongClickListener() != null) {
view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
return getOnItemLongClickListener().onItemLongClick(null, v, baseViewHolder.getLayoutPosition(),v.getId());
}
});
}
}
}

0 comments on commit 8d8b624

Please sign in to comment.