Reputation: 1986
I have an Endless RecyclerView
with library PullLoadView
this RecyclerView
is fill the layout, I want to when this RecyclerView
load all its items and reach the end of end, I load another RecyclerView
at bottom of it, which has its own adapter and row layout and continue .
something like this application I need :
first RecyclerView
:
first RecyclerView
reaches end and new RecyclerView
show up
new RecyclerView
continue the first RecyclerView
in full layour screen
xml Code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvOne"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvTwo"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Upvotes: 1
Views: 784
Reputation: 465
Use ListView as your bottom View and in your ListView header put RecycerView
list_sample.xml (This is your main layout for activity set content)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ListView
android:id="@+id/list_sample"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
header_recycler.xml(List view header layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/list_header"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
item_header.xml(items for header's list i.e. recyclerview one)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/item_header_regular"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#FF2255" />
</LinearLayout>
list_item.xml (List view's item)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="50dp" />
</LinearLayout>
HeaderRecyclerView.java (RecyclerView adapter)
import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
public class HeaderRecyclerView extends RecyclerView.Adapter<HeaderRecyclerView.HeaderHolder> {
private final Context context;
private List<String> items;
public HeaderRecyclerView(List<String> items, Context context) {
this.items = items;
this.context = context;
}
@Override
public HeaderHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_header, parent, false);
return new HeaderHolder(v);
}
@Override
public void onBindViewHolder(HeaderHolder holder, int position) {
String item = items.get(position);
holder.textView.setText(item);
}
@Override
public int getItemCount() {
if (items == null) {
return 0;
}
return items.size();
}
class HeaderHolder extends RecyclerView.ViewHolder {
TextView textView;
HeaderHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.item_header_regular);
}
}
}
BottomListAdapter.java (ListView adapter)
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
public class BottomListAdapter extends BaseAdapter {
private List<String> items = new ArrayList<>();
private Context context;
public BottomListAdapter(List<String> items, Context context) {
this.items = items;
this.context = context;
}
@Override
public int getCount() {
return items.size();
}
@Override
public String getItem(int i) {
return items.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View convertView, ViewGroup viewGroup) {
TextView txtView;
if (convertView == null) {
convertView = LayoutInflater.from(context)
.inflate(R.layout.list_item, viewGroup, false);
txtView = (TextView) convertView.findViewById(R.id.text);
convertView.setTag(new ViewHolder(txtView));
} else {
ViewHolder viewHolder = (ViewHolder) convertView.getTag();
txtView = viewHolder.txtView;
}
String string = getItem(i);
txtView.setText(string);
return convertView;
}
private static class ViewHolder {
public final TextView txtView;
public ViewHolder(TextView txtView) {
this.txtView = txtView;
}
}
}
In Your onCreate use the below to initialize as follwing
ListView listView = (ListView) findViewById(R.id.list_sample);
View view = getLayoutInflater().inflate(R.layout.header_recycler, null);
RecyclerView headerList = (RecyclerView) view.findViewById(R.id.list_header);
List<String> strings = new ArrayList<>();
for (int i = 0; i < 50; i++) {
strings.add(i + "");
}
headerList.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
headerList.setAdapter(new HeaderRecyclerView(strings, this));
listView.addHeaderView(view);
listView.setAdapter(new BottomListAdapter(strings, this));
Upvotes: 0
Reputation: 1884
Replace your xml
source with the below source
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:scrollbars="none">
<LinearLayout
android:id="@+id/activity_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvOne"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvTwo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Upvotes: 1
Reputation: 1343
Put them in a NestedScrollView with a vertically oriented LinearLayout and Disable their scrolling by setting their linearlayout manager like this.
LinearLayoutManager mLayoutManager = new LinearLayoutManager(this) {
@Override
public boolean canScrollVertically() {
return false;
}
};
Upvotes: 0