Skip to content

Commit

Permalink
click event add
Browse files Browse the repository at this point in the history
  • Loading branch information
XinYiWorld committed Mar 29, 2017
1 parent 6e7dff9 commit 685b3e5
Show file tree
Hide file tree
Showing 20 changed files with 312 additions and 144 deletions.
Binary file modified .gradle/2.14.1/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified .gradle/2.14.1/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified .gradle/2.14.1/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file not shown.
Binary file modified .gradle/2.14.1/taskArtifacts/taskArtifacts.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

308 changes: 178 additions & 130 deletions .idea/workspace.xml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions build/intermediates/dex-cache/cache.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
jumboMode="true"
optimize="true"
revision="25.0.1"
sha1="0235d081da2159d1ce976d4b2cd936414b0f951a">
sha1="fb1b041d27f41aee8b5b438ebe78f94e6bd18f99">
<dex dex="D:\DevWork\Code\Demos\QD\PublishedCode\CZSuperAdapter\samples\build\intermediates\transforms\dex\debug\folders\1000\10\instant-run_60d903a5ac4a67793fcd4d56d51422b5ef47640f\classes.dex" />
</item>
<item
Expand Down Expand Up @@ -52,7 +52,7 @@
jumboMode="true"
optimize="true"
revision="25.0.1"
sha1="cd6fad6f7329176c73ad75298d55c4302c7acf00">
sha1="782d75647b8c22c2e1cc24c14a30c587fe992176">
<dex dex="D:\DevWork\Code\Demos\QD\PublishedCode\CZSuperAdapter\samples\build\intermediates\transforms\dex\debug\folders\1000\10\instant-run-bootstrap_481909628a2c2acfebcbebf06629022aa21c6af0\classes.dex" />
</item>
<item
Expand Down
16 changes: 8 additions & 8 deletions libary/libary.iml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
Expand All @@ -83,6 +75,14 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class CZSuperAdapter<T> extends ICRUDAdapter<T> implements IAddTypeMaker,
private final LockObserver lockObserver;
private final TypeManager typeManager;

private CommonViewHolder.OnItemClickListener onItemClickListener;
private CommonViewHolder.OnItemLongClickListener onItemLongClickListener;

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
Expand Down Expand Up @@ -159,7 +162,14 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
multiTypeMaker.bindViewHolder(commonViewHolder, multiTypeMaker.getData(), MultiTypeMaker.TYPE_HEADER, position - refreshControllerCount);
break;
case MultiTypeMaker.TYPE_NORMAL: //主体布局
multiTypeMaker.bindViewHolder((CommonViewHolder) holder, mNormalData.get(normalViewStartPosition), multiTypeMaker.getType(normalViewStartPosition), normalViewStartPosition);
multiTypeMaker.bindViewHolder(commonViewHolder, mNormalData.get(normalViewStartPosition), multiTypeMaker.getType(normalViewStartPosition), normalViewStartPosition);
//绑定点击事件
if(onItemClickListener != null){
commonViewHolder.setOnItemClickListener(onItemClickListener,normalViewStartPosition);
}
if(onItemLongClickListener != null){
commonViewHolder.setOnItemLongClickListener(onItemLongClickListener,normalViewStartPosition);
}
break;
case MultiTypeMaker.TYPE_FOOTER: //脚布局 (有可能被主体数据利用了)
multiTypeMaker = typeManager.getFooter(position - mNormalData.size() - refreshControllerCount - headerCount);
Expand Down Expand Up @@ -273,4 +283,25 @@ public boolean removeFooter(MultiTypeMaker footer) {
}
return success;
}



/**
* set the on item click listener
* 设置Item的点击事件
* @param listener listener
*/
public void setOnItemClickListener(final CommonViewHolder.OnItemClickListener listener ) {
this.onItemClickListener = listener;
}


/**
* set the on item long click listener
* 设置Item的长点击事件
* @param listener listener
*/
public void setOnItemLongClickListener(final CommonViewHolder.OnItemLongClickListener listener) {
this.onItemLongClickListener = listener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* func:
*/

public class CommonViewHolder extends RecyclerView.ViewHolder {
public class CommonViewHolder extends RecyclerView.ViewHolder{
private SparseArray<View> mViews;
private MultiTypeMaker multiTypeMaker;
private ViewGroup parent;
Expand Down Expand Up @@ -46,4 +46,74 @@ public ViewGroup getParent() {
public void setParent(ViewGroup parent) {
this.parent = parent;
}


/**
* set the on item click listener
* 设置Item的点击事件
*
* @param listener listener
* @param position position
*/
public void setOnItemClickListener(final OnItemClickListener listener, final int position) {
if (listener == null) {
this.itemView.setOnClickListener(null);
} else {
this.itemView.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
listener.onItemClick(v, position);
}
});
}
}


/**
* set the on item long click listener
* 设置Item的长点击事件
*
* @param listener listener
* @param position position
*/
public void setOnItemLongClickListener(final OnItemLongClickListener listener, final int position) {
if (listener == null) {
this.itemView.setOnLongClickListener(null);
} else {
this.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override public boolean onLongClick(View v) {
return listener.onItemLongClick(v, position);
}
});
}
}


/**
* the click listeners callback
* 点击事件回调
*/
public interface OnItemClickListener {
/**
* on item click call back
*
* @param convertView convertView
* @param position position
*/
void onItemClick(View convertView, int position);
}

/**
* the long click listeners callback
* 长点击事件回调
*/
public interface OnItemLongClickListener {
/**
* on item long click call back
*
* @param convertView convertView
* @param position position
* @return true false
*/
boolean onItemLongClick(View convertView, int position);
}
}
1 change: 0 additions & 1 deletion samples/samples.iml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/builds" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
Expand Down
20 changes: 20 additions & 0 deletions samples/src/main/java/xinyi/com/samples/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

import com.xinyi.czsuperadapter.AVLoadingIndicatorView;
import com.xinyi.czsuperadapter.interfaces.LoaderListener;
Expand Down Expand Up @@ -67,6 +69,24 @@ public void bindViewHolder(CommonViewHolder holder, String data, int viewType, i
}
}
});

mAdapter.setOnItemClickListener(new CommonViewHolder.OnItemClickListener() {
@Override
public void onItemClick(View convertView, int position) {
Toast.makeText(MainActivity.this, position + "", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onItemClick: " + position);
}
});

mAdapter.setOnItemLongClickListener(new CommonViewHolder.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(View convertView, int position) {
Toast.makeText(MainActivity.this, position + "", Toast.LENGTH_SHORT).show();
Log.i(TAG, "onItemLongClick: " + position);
return true;
}
});

recyclerView.setLayoutManager(new LinearLayoutManager(this));
// set divider
DividerLine dividerLine = new DividerLine(DividerLine.VERTICAL);
Expand Down

0 comments on commit 685b3e5

Please sign in to comment.