Skip to content

Commit

Permalink
fixbug #1078
Browse files Browse the repository at this point in the history
  • Loading branch information
ChadCym committed Apr 28, 2017
1 parent b33fac7 commit 749371b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 26 deletions.
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".PullToRefreshUseActivity"/>
<activity android:name=".WelcomeActivity"
>
<activity android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand All @@ -32,7 +31,9 @@
</activity>
<activity android:name=".base.BaseActivity">
</activity>
<activity android:name=".HomeActivity" android:launchMode="singleTask">
<activity
android:name=".HomeActivity"
android:launchMode="singleTask">
</activity>
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.chad.baserecyclerviewadapterhelper;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Toast;

Expand All @@ -28,23 +28,10 @@ protected void onCreate(Bundle savedInstanceState) {
setBackBtn();
setTitle("Section Use");
mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));
mData = DataServer.getSampleData();
SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
// mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {
//
// @Override
// public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
//
// }
//
// @Override
// public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
//
// }
//
//
// });

sectionAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
@Override
public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public void onClick(View v) {
case TYPE_PERSON:
final Person person = (Person)item;
holder.setText(R.id.tv, person.name + " parent pos: " + getParentPosition(person));
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int cp = getParentPosition(person);
((Level1Item)getData().get(cp)).removeSubItem(person);
getData().remove(holder.getLayoutPosition());
notifyItemRemoved(holder.getLayoutPosition());
}
});
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<resources tools:ignore="MissingTranslation" xmlns:tools="http://schemas.android.com/tools">
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string name="app_name">BRVAH</string>
<string name="title_activity_header_and_footer_use">HeaderAndFooterUseActivity</string>
<string name="error">Network error</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -747,18 +747,23 @@ public int getSpanSize(int position) {
return 1;
}
if (mSpanSizeLookup == null) {
return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type ==
LOADING_VIEW) ? gridManager.getSpanCount() : 1;
return isFixedViewType(type) ? gridManager.getSpanCount() : 1;
} else {
return (type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type ==
LOADING_VIEW) ? gridManager.getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager,
return (isFixedViewType(type)) ? gridManager.getSpanCount() : mSpanSizeLookup.getSpanSize(gridManager,
position - getHeaderLayoutCount());
}
}


});
}
}

protected boolean isFixedViewType(int type) {
return type == EMPTY_VIEW || type == HEADER_VIEW || type == FOOTER_VIEW || type ==
LOADING_VIEW;
}

/**
* if asFlow is true, footer/header will arrange like normal item view.
* only works when use {@link GridLayoutManager},and it will ignore span size.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ public abstract class BaseSectionQuickAdapter<T extends SectionEntity, K extends
* @param layoutResId The layout resource id of each item.
* @param data A new list is created out of this one to avoid mutable list
*/
public BaseSectionQuickAdapter( int layoutResId, int sectionHeadResId, List<T> data) {
public BaseSectionQuickAdapter(int layoutResId, int sectionHeadResId, List<T> data) {
super(layoutResId, data);
this.mSectionHeadResId = sectionHeadResId;
}

@Override
protected int getDefItemViewType(int position) {
return mData.get(position).isHeader ? SECTION_HEADER_VIEW : 0;
return mData.get(position).isHeader ? SECTION_HEADER_VIEW : 0;
}

@Override
Expand All @@ -41,6 +41,11 @@ protected K onCreateDefViewHolder(ViewGroup parent, int viewType) {
return super.onCreateDefViewHolder(parent, viewType);
}

@Override
protected boolean isFixedViewType(int type) {
return super.isFixedViewType(type)|| type == SECTION_HEADER_VIEW;
}

@Override
public void onBindViewHolder(K holder, int positions) {
switch (holder.getItemViewType()) {
Expand Down

0 comments on commit 749371b

Please sign in to comment.