Next item appearing after scolling in RecyclerView - android

I have created RecyclerView. When it renders on screen it shows only one item per screen. I can see next item when I scroll down RecyclerView. Here is my code
public class LeaveStatusViewAdapter extends RecyclerView
.Adapter<LeaveStatusViewAdapter
.DataObjectHolder> {
private static String LOG_TAG = "MyRecyclerViewAdapter";
private ArrayList<Employee> mDataset;
private static MyClickListener myClickListener;
public static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView startDate;
TextView endDate;
TextView leaveType;
TextView leaveDays;
TextView leaveReason;
TextView leaveStatus;
public DataObjectHolder(View itemView) {
super(itemView);
startDate = (TextView) itemView.findViewById(R.id.textView_StartDate);
endDate = (TextView) itemView.findViewById(R.id.textView_EndDate);
leaveType = (TextView) itemView.findViewById(R.id.textView_LeaveType);
leaveDays = (TextView) itemView.findViewById(R.id.textView_LeaveDays);
leaveReason = (TextView) itemView.findViewById(R.id.textView_LeaveReason);
leaveStatus = (TextView) itemView.findViewById(R.id.textView_LeaveStatus);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
#Override
public void onClick(View v) {
myClickListener.onItemClick(getAdapterPosition(), v);
}
}
public void setOnItemClickListener(MyClickListener myClickListener) {
this.myClickListener = myClickListener;
}
public LeaveStatusViewAdapter(ArrayList<Employee> myDataset) {
mDataset = myDataset;
}
#Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_view_row, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
#Override
public void onBindViewHolder(DataObjectHolder holder, int position) {
holder.startDate.setText(mDataset.get(position).getLeaveStartDate());
holder.endDate.setText(mDataset.get(position).getLeavesEndDate());
holder.leaveType.setText(mDataset.get(position).getLeaveType());
holder.leaveDays.setText(mDataset.get(position).getLeaveDays());
holder.leaveReason.setText(mDataset.get(position).getLeaveReason());
holder.leaveStatus.setText(mDataset.get(position).getLeaveStatus());
}
public void addItem(Employee dataObj, int index) {
mDataset.add(index, dataObj);
notifyItemInserted(index);
}
public void deleteItem(int index) {
mDataset.remove(index);
notifyItemRemoved(index);
}
#Override
public int getItemCount() {
return mDataset.size();
}
public interface MyClickListener {
public void onItemClick(int position, View v);
}
}
Following is activity class
public class LeaveStatusActivity extends AppCompatActivity {
private RecyclerView mRecyclerView;
private RecyclerView.Adapter mAdapter;
private RecyclerView.LayoutManager mLayoutManager;
private static String LOG_TAG = "CardViewActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leave_status);
mRecyclerView = (RecyclerView) findViewById(R.id.my_recycler_view);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);
mAdapter = new LeaveStatusViewAdapter(getDataSet());
mRecyclerView.setAdapter(mAdapter);
}
#Override
protected void onResume() {
super.onResume();
((LeaveStatusViewAdapter) mAdapter).setOnItemClickListener(new LeaveStatusViewAdapter
.MyClickListener() {
#Override
public void onItemClick(int position, View v) {
Log.i(LOG_TAG, " Clicked on Item " + position);
}
});
}
private ArrayList<Employee> getDataSet() {
ArrayList results = new ArrayList<Employee>();
for (int index = 0; index < 3; index++) {
Employee obj = new Employee(" : 15/07/2016",
" : 20/07/2016"," : EL: Earned Leave"," : 5"," : Not feeeling well"," : Pending");
results.add(index, obj);
}
return results;
}
}
Following is Layout files
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context="com.leave.mcgm.mcgmleavemanagement.LeaveStatusActivity">
<android.support.v7.widget.RecyclerView
android:id="#+id/my_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"/>
</LinearLayout>
Following custom view for each item in RecyclerView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/lbl_StartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:text="Start Date"/>
<TextView
android:id="#+id/textView_StartDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/lbl_StartDate" />
<TextView
android:id="#+id/lbl_EndDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textStyle="bold"
android:layout_marginStart="24dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView_LeaveReason" />
<TextView
android:id="#+id/textView_EndDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/lbl_EndDate"
android:layout_alignBottom="#+id/lbl_EndDate"
android:layout_toEndOf="#+id/lbl_EndDate" />
<TextView
android:id="#+id/lbl_LeaveType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text="LeaveType"
android:layout_below="#+id/lbl_EndDate"
android:layout_alignParentStart="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView_LeaveType"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_alignBaseline="#+id/lbl_LeaveType"
android:layout_alignBottom="#+id/lbl_LeaveType"
android:layout_toEndOf="#+id/lbl_LeaveType" />
<TextView
android:id="#+id/lbl_LeaveDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Leave Days"
android:singleLine="true"
android:layout_below="#+id/lbl_EndDate"
android:layout_alignStart="#+id/lbl_EndDate"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView_LeaveDays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_alignBaseline="#+id/lbl_LeaveDays"
android:layout_alignBottom="#+id/lbl_LeaveDays"
android:layout_toEndOf="#+id/lbl_LeaveDays" />
<TextView
android:id="#+id/lbl_LeaveReason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Leave Reason"
android:singleLine="true"
android:layout_alignTop="#+id/textView_LeaveReason"
android:layout_alignParentStart="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView_LeaveReason"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_below="#+id/textView_LeaveDays"
android:layout_toEndOf="#+id/lbl_LeaveReason" />
<TextView
android:id="#+id/lbl_LeaveStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Leave Status"
android:singleLine="true"
android:layout_alignBaseline="#+id/textView_LeaveStatus"
android:layout_alignBottom="#+id/textView_LeaveStatus"
android:layout_alignParentStart="true"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView_LeaveStatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:text=""
android:layout_below="#+id/lbl_LeaveReason"
android:layout_toEndOf="#+id/lbl_LeaveReason"
android:textAllCaps="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
Am I missing something here??

You should change the view of each element of the list to android:layout_height="wrap_content"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp">
.....
</LinearLayout>
When you use android:layout_height="match_parent" every item of the list will try to use the maximum space possible in the screen

Related

Listview returning the wrong postion with BaseSwipeAdapter

I am using a listview with swipelayout (daimajia library) and my listview is scrolling...
My problem is when I swipe listview item and click on button in it ,it returns me wrong position..
Do you have any idea of how to solve this??
This is my adapter
public View generateView(final int position, final ViewGroup parent) {
View v =
LayoutInflater.from(parent.getContext()).inflate(R.layout.ledger_layout, null);
SwipeLayout swipeLayout = (SwipeLayout) v.findViewById(getSwipeLayoutResourceId(position));
swipeLayout.addSwipeListener(new SimpleSwipeListener() {
#Override
public void onOpen(SwipeLayout layout) {
}
});
swipeLayout.setOnDoubleClickListener(new
SwipeLayout.DoubleClickListener() {
#Override
public void onDoubleClick(SwipeLayout layout, boolean surface) {
Toast.makeText(context, "DoubleClick",
Toast.LENGTH_SHORT).show();
}
});
return v;
}
I think your implementation of getView method is messy. Try this.
ListAdapter Java class.
package com.dev4solutions.myapplication.activities;
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 android.widget.Toast;
import com.daimajia.swipe.SimpleSwipeListener;
import com.daimajia.swipe.SwipeLayout;
import com.dev4solutions.myapplication.R;
import java.util.ArrayList;
class ListAdapter extends BaseAdapter {
private ArrayList<String> strings;
private Context mContext;
public ListAdapter(Context context, ArrayList<String> list) {
strings = list;
mContext = context;
}
#Override
public int getCount() {
return strings.size();
}
#Override
public Object getItem(int i) {
return strings.get(i);
}
#Override
public long getItemId(int i) {
return i;
}
#Override
public View getView(final int position, View view, ViewGroup viewGroup) {
ViewHolder viewHolder = null;
if (view == null) {
view = LayoutInflater.from(mContext).inflate(R.layout.ledger_layout, null);
viewHolder = new ViewHolder();
viewHolder.swipeLayout = view.findViewById(R.id.swipe);
viewHolder.textView = view.findViewById(R.id.text_data);
viewHolder.delete = view.findViewById(R.id.delete);
view.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.textView.setText(String.valueOf("Swipe Layout : " + position));
viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
#Override
public void onOpen(SwipeLayout layout) {
Toast.makeText(mContext, "onOpen : " + position,
Toast.LENGTH_SHORT).show();
}
});
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
#Override
public void onDoubleClick(SwipeLayout layout, boolean surface) {
Toast.makeText(mContext, "DoubleClick : " + position,
Toast.LENGTH_SHORT).show();
}
});
viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
#Override
public void onDoubleClick(SwipeLayout layout, boolean surface) {
Toast.makeText(mContext, "DoubleClick : " + position,
Toast.LENGTH_SHORT).show();
}
});
viewHolder.delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(mContext, "onDelete Click : " + position,
Toast.LENGTH_SHORT).show();
}
});
return view;
}
// view holder for managing to recycle of view
public static class ViewHolder {
SwipeLayout swipeLayout;
TextView textView;
View delete;
}
}
ledger_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
swipe:leftEdgeSwipeOffset="0dp"
swipe:rightEdgeSwipeOffset="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#FF5534"
android:gravity="center"
android:tag="Bottom3"
android:weightSum="10">
<ImageView
android:id="#+id/trash"
android:layout_width="27dp"
android:layout_height="30dp"
android:layout_weight="1"
android:src="#android:drawable/ic_delete" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:text="Delete Item?"
android:textColor="#fff"
android:textSize="17sp" />
<Button
android:id="#+id/delete"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="4"
android:background="#ffffff"
android:text="Yes,Delete"
android:textColor="#FF5534" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cac6c6"
android:padding="10dp">
<TextView
android:id="#+id/position"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/text_data"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:tag="Hover"
android:text="Do not, for one repulse, forgo the purpose that you resolved to effort. " />
</LinearLayout>
</com.daimajia.swipe.SwipeLayout>
using the way which is marked as an answer will work but there is an another way of doing it too...
adapter class
public class testadapter1 extends RecyclerSwipeAdapter<testadapter1.SimpleViewHolder> {
public static final String TAG = testadapter1.class.getSimpleName();
private static SwipLayoutListener swipLayoutListener;
private static ClickListener clickListener;
String[] time;
Animation animSlide;
boolean ANIM_FLAG = true;
private int lastVisibleItem, totalItemCount;
private boolean loading;
private OnLoadMoreListener onLoadMoreListener;
private int visibleThreshold = 5;
private String phone;
private String email;
public static class SimpleViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, SwipeRefreshLayout.OnRefreshListener {
SwipeLayout swipeLayout;
TextView text;
TextView info;
TextView swipeImage;
LinearLayout linearLayout;
ImageView imageView;
#Override
public void onClick(View view) {
clickListener.onItemClick(getAdapterPosition(), view);
Log.e("position", String.valueOf(getAdapterPosition()));
}
public SimpleViewHolder(View itemView) {
super(itemView);
swipeLayout = (SwipeLayout) itemView.findViewById(R.id.swipe);
text = (TextView) itemView.findViewById(R.id.input_cname);
txtdate = (TextView) itemView.findViewById(R.id.date);
id = (TextView) itemView.findViewById(R.id.input_cid);
Typeface iconFont = FontManager.getTypeface(mContext, FontManager.FONTAWESOME);
FontManager.markAsIconContainer(itemView.findViewById(R.id.swipe), iconFont);
swipeImage = itemView.findViewById(R.id.swipeIcon);
imageView = new ImageView(mContext);
call = (TextView) itemView.findViewById(R.id.call_btn);
sms = (TextView) itemView.findViewById(R.id.sms_btn);
mail = (TextView) itemView.findViewById(R.id.email_btn);
info = (TextView) itemView.findViewById(R.id.detail_btn);
call.setTypeface(iconFont);
sms.setTypeface(iconFont);
mail.setTypeface(iconFont);
info.setTypeface(iconFont);
swipeLayout.addDrag(SwipeLayout.DragEdge.Left, linearLayout);
itemView.setOnClickListener(this);
swipeLayout.addSwipeListener(new SimpleSwipeListener() {
#Override
public void onOpen(SwipeLayout layout) {
if (swipLayoutListener != null) {
swipLayoutListener.onOpen(layout, getAdapterPosition());
}
}
});
}
}
private static Context mContext;
ArrayList<HashMap<String, String>> mDataset;
public testadapter1(Context mContext, ArrayList<HashMap<String, String>> objects, RecyclerView listView) {
this.mContext = mContext;
this.mDataset = objects;
if (listView.getLayoutManager() instanceof LinearLayoutManager) {
final LinearLayoutManager linearLayoutManager = (LinearLayoutManager) listView
.getLayoutManager();
listView
.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView listView,
int dx, int dy) {
super.onScrolled(listView, dx, dy);
totalItemCount = linearLayoutManager.getItemCount();
lastVisibleItem = linearLayoutManager
.findLastVisibleItemPosition();
if (!loading
&& totalItemCount <= (lastVisibleItem + visibleThreshold)) {
// End has been reached
// Do something
if (onLoadMoreListener != null) {
onLoadMoreListener.onLoadMore();
}
loading = true;
}
}
});
}
}
#Override
public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.ledger_layout, parent, false);
return new SimpleViewHolder(view);
}
public interface ClickListener {
void onItemClick(int position, View v);
}
#Override
public void onBindViewHolder(final SimpleViewHolder viewHolder, final int position) {
viewHolder.txtdate.setText(mDataset.get(position).get("date"));
viewHolder.id.setText("Amount: ₹ " + viewHolder.info.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// HashMap<String, String> mDataset = getItem1(position);
Intent intent = new Intent(mContext, LedgerDetailActivity.class);
intent.putExtra("ledger_name", String.valueOf(mDataset.get(position).get("ledger_name")));
// Log.e("intent", mDataset.get("ledger_name"));
mContext.startActivity(intent);
}
});
}
#Override
public int getItemCount() {
if (mDataset == null) {
Log.d(TAG, "getCount: 0");
return 0;
} else {
Log.d(TAG, "getCount: " + mDataset.size());
return mDataset.size();
}
}
#Override
public int getSwipeLayoutResourceId(int position) {
return R.id.swipe;
}
public void addSwipeListener(SwipLayoutListener swipLayoutListener) {
testadapter1.swipLayoutListener = swipLayoutListener;
}
public interface SwipLayoutListener {
void onOpen(SwipeLayout layout, int position);
}
fragment layout
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/frame3"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="#+id/list_ledger"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"/>
<!-- Adding bottom sheet after main content -->
</android.support.v4.widget.SwipeRefreshLayout>
adapter layout
<?xml version="1.0" encoding="utf-8"?>
<com.daimajia.swipe.SwipeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:swipe="http://schemas.android.com/apk/res-auto"
android:id="#+id/swipe"
android:layout_width="match_parent"
android:layout_height="wrap_content"
swipe:leftEdgeSwipeOffset="0dp"
swipe:rightEdgeSwipeOffset="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimaryDark"
android:gravity="center"
android:weightSum="7">
<RelativeLayout
android:id="#+id/relativeLayoutSms"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<com.mikepenz.iconics.view.IconicsTextView
android:id="#+id/call_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:text="#string/icon_phone"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/call_btn"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="Call"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayoutCall"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<com.mikepenz.iconics.view.IconicsTextView
android:id="#+id/sms_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:text="#string/icon_sms"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/sms_btn"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="SMS"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayoutMail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<com.mikepenz.iconics.view.IconicsTextView
android:id="#+id/email_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:text="#string/icon_mail"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/email_btn"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="Email"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayoutInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">
<com.mikepenz.iconics.view.IconicsTextView
android:id="#+id/detail_btn"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:shadowDx="3"
android:shadowDy="3"
android:shadowRadius="1"
android:text="#string/icon_info"
android:textColor="#color/white"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/detail_btn"
android:layout_centerHorizontal="true"
android:gravity="center"
android:paddingTop="5dp"
android:text="Details"
android:textColor="#color/white"
android:textSize="12sp"
android:textStyle="bold" />
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp">
<TextView
android:id="#+id/input_cname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignStart="#+id/date"
android:layout_marginEnd="5dp"
android:layout_toStartOf="#id/amount"
android:ellipsize="end"
android:maxLines="1"
android:textColor="#color/colorAccent"
android:textSize="16sp" />
<TextView
android:id="#+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/input_cname"
android:layout_marginStart="10dp"
android:paddingTop="2dp"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/input_cid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerInParent="true"
android:layout_marginEnd="2dp"
android:layout_marginStart="10dp"
android:paddingEnd="5dp"
android:textAlignment="viewEnd"
android:textColor="#color/black"
android:textSize="14sp" />
<TextView
android:id="#+id/gp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignStart="#+id/input_cid"
android:layout_below="#+id/input_cname"
android:textAlignment="viewEnd"
android:textColor="#color/bb_darkBackgroundColor"
android:textSize="14sp"
android:visibility="gone" />
<TextView
android:id="#+id/swipeIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_below="#id/gp"
android:layout_marginTop="14dp"
android:paddingStart="6dp"
android:visibility="gone" />
</RelativeLayout>
It's been a long time but I had the same issue. It took hours to solve the problem but the solution is here. This WARNING is from the daimajia's wiki.
ATTENTION: Never bind listeners or fill values in generateView. Just generate the view and do everything else in fillValues (e.g using your holder class) See issues #14 and #17
You can find detailed solution here : Solution to your position problem from daimajia's wiki
And sample code is like this :
//ATTENTION: Never bind listener or fill values in generateView.
// You have to do that in fillValues method.
#Override
public View generateView(int position, ViewGroup parent) {
return LayoutInflater.from(mContext).inflate(R.layout.grid_item, null);
}
#Override
public void fillValues(int position, View convertView) {
TextView t = (TextView)convertView.findViewById(R.id.position);
t.setText((position + 1 )+".");
}
You should do everything in fillValues() function. position value here is always right.
Just follow this rule and everything will be fine with your Swipe ListView.

StaggeredGridLayoutManager changing item size on scroll

I am searching for a long time on net. But no use. Please help or try to give some ideas how to solve this problem.
1. Bug Description
image link:https://i.stack.imgur.com/ixvdB.jpg
"left":Run the apk
"Right":When I swipe down, the size of the items is changing.
2. Code
MainActivity.java
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
List<Member> memberList = new ArrayList<>();
memberList.add(new Member(1, R.drawable.baishatunbeach1, "白沙屯海灘1"));
//add Members
recyclerView.setAdapter(new MemberAdapter(this, memberList));
}
private class MemberAdapter extends RecyclerView.Adapter<MemberAdapter.ViewHolder> {
private Context context;
private List<Member> memberList;
MemberAdapter(Context context, List<Member> memberList) {
this.context = context;
this.memberList = memberList;
}
#Override
public MemberAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.recyclerview_cardview_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(MemberAdapter.ViewHolder holder, int position) {
final Member member = memberList.get(position);
holder.imageId.setImageResource(member.getImage());
holder.textId.setText(String.valueOf(member.getId()));
holder.textName.setText(member.getName());
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
ImageView imageView = new ImageView(context);
imageView.setImageResource(member.getImage());
Toast toast = new Toast(context);
toast.setView(imageView);
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
}
});
}
#Override
public int getItemCount() {
return memberList.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
ImageView imageId;
TextView textId, textName;
ViewHolder(View itemView) {
super(itemView);
imageId = (ImageView) itemView.findViewById(R.id.imageId);
textId = (TextView) itemView.findViewById(R.id.textId);
textName = (TextView) itemView.findViewById(R.id.textName);
}
}
}
}
activity_main.xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v7.widget.RecyclerView
android:id="#+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
recyclerview_cardview_item.xml
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="6dp"
android:padding="6dp"
app:cardBackgroundColor="#ffdddddd"
app:cardCornerRadius="28dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="#+id/imageId"
android:layout_width="120dp"
android:layout_height="160dp"
android:layout_marginStart="16dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/textId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginStart="20dp" />
<TextView
android:id="#+id/textName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:layout_marginStart="24dp" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
You need to change the height of cardview and linearlayout to wrap_content
<android.support.v7.widget.CardView
android:id="#+id/cardview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:padding="6dp"
app:cardBackgroundColor="#ffdddddd"
app:cardCornerRadius="28dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

Firebase RecyclerView expandable view not working (Do not wish to use any 3rd Party Library)

I have used a FirebaseRecyclerAdapter in my application for displaying a series of events. When i select an event form the recycler view it must expand the recycler view item and show me the details and other items of that event such as dates, description and others. I used a concept from Google I/O 2016 but could't land anywhere as my event is not showing only. I want only a specific set of items to be displayed when expanded.
EventView.java
public class EventView extends AppCompatActivity {
DatabaseReference databaseReference;
RecyclerView recyclerView;
int mExpandedPosition = -1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_event_view);
databaseReference = FirebaseDatabase.getInstance().getReference().child("ApprovedEvents");
recyclerView = (RecyclerView) findViewById(R.id.request_EventList);
//Avoid unnecessary layout passes by setting setHasFixedSize to true
recyclerView.setHasFixedSize(true);
//Select the type of layout manager you would use for your recyclerView
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
#Override
protected void onStart() {
super.onStart();
final String event_cat = getIntent().getStringExtra("Category");
FirebaseRecyclerAdapter<Event, RequestViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Event, RequestViewHolder>(
Event.class,
R.layout.events_list_row,
RequestViewHolder.class,
databaseReference.orderByChild("category").equalTo(event_cat)
) {
#Override
protected void populateViewHolder(RequestViewHolder viewHolder, Event model, int position) {
viewHolder.setTitle(model.getTitle());
viewHolder.setDesc(model.getDesc());
viewHolder.setCategory(model.getCategory());
viewHolder.setLocation(model.getLocation());
viewHolder.setPrice(model.getPrice());
viewHolder.setImageUrl(getApplicationContext(), model.getImageUrl());
viewHolder.imageButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(EventView.this, "Image Selected", Toast.LENGTH_SHORT).show();
}
});
}
#Override
public void onBindViewHolder(RequestViewHolder viewHolder, final int position) {
super.onBindViewHolder(viewHolder, position);
final boolean isExpanded = position == mExpandedPosition;
viewHolder.mView.setVisibility(isExpanded?View.VISIBLE:View.GONE);
viewHolder.mView.setActivated(isExpanded);
viewHolder.mView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mExpandedPosition = isExpanded ? -1:position;
TransitionManager.beginDelayedTransition(recyclerView);
notifyDataSetChanged();
}
});
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
public static class RequestViewHolder extends RecyclerView.ViewHolder {
View mView;
ImageView imageButton;
public RequestViewHolder(View itemView) {
super(itemView);
mView = itemView;
imageButton = (ImageView) mView.findViewById(R.id.request_image);
}
public void setTitle(String title) {
TextView a_title = (TextView) mView.findViewById(R.id.request_title);
a_title.setText(title);
}
public void setDesc(String desc) {
TextView a_desc = (TextView) mView.findViewById(R.id.request_desc);
a_desc.setText(desc);
}
public void setLocation(String location) {
TextView a_desc = (TextView) mView.findViewById(R.id.request_location);
a_desc.setText(location);
}
public void setCategory(String category) {
TextView a_category = (TextView) mView.findViewById(R.id.request_category);
a_category.setText(category);
}
public void setPrice(String price) {
TextView a_price = (TextView) mView.findViewById(R.id.request_price);
a_price.setText(price);
}
public void setImageUrl(Context ctx, String imageUrl) {
ImageView a_image = (ImageView) mView.findViewById(R.id.request_image);
Picasso.with(ctx).load(imageUrl).into(a_image);
}
}
}
events_list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<android.support.v7.widget.CardView
android:id="#+id/card_view"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/request_category"
android:textStyle="bold"
android:textSize="15dp"
android:padding="5dp"
android:layout_gravity="left"
android:text="Category will come here"/>
<TextView
android:layout_width="191dp"
android:layout_height="wrap_content"
android:id="#+id/request_location"
android:textSize="15dp"
android:gravity="right"
android:layout_gravity="right"
android:text="Location will come here"
android:padding="5dp"
android:textStyle="bold"/>
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/request_title"
android:layout_marginTop="300dp"
android:text="Title will come here "
android:padding="10dp"
android:textStyle="bold"
android:textSize="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/request_desc"
android:text="Desc will come here "
android:layout_marginTop="250dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp" />
<ImageView
android:layout_width="match_parent"
android:layout_height="275dp"
android:id="#+id/request_image"
android:src="#drawable/abc_btn_check_material"
android:adjustViewBounds="true"
android:clickable="true"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Price will come here"
android:id="#+id/request_price"
android:layout_marginTop="270dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"/>
</android.support.v7.widget.CardView>
</LinearLayout>
activity_event_view.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
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"
tools:context="com.example.admin.college20.EventView">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/request_EventList"
android:clickable="true"/>
</RelativeLayout>

onCreateViewHolder not called RecyclerView

I am using Recyclerview and my onCreateViewHolder and onBindViewHolder are not called. I am getting the data but it is not displaying.
My adapter class
public class DishesAdapter extends RecyclerView.Adapter<DishesAdapter.MyViewHolder> {
private Context mContext;
List<List> DialogList = new ArrayList<List>();
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView dishnames;
public RatingBar dishratings;
public ImageView dishimages;
private ImageLoader mLoader;
public MyViewHolder(View view) {
super(view);
Log.d("follower2","hi");
dishnames = (TextView)view.findViewById(R.id.dishname);
dishimages = (ImageView)view.findViewById(R.id.dishimage);
dishratings=(RatingBar)view.findViewById(R.id.dishrating);
}
}
public DishesAdapter(Context mContext, List objects) {
super();
Log.d("follower1","hi");
this.mContext = mContext;
this.DialogList = objects;
Log.d("follower1",objects.toString());
}
#Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(mContext)
.inflate(R.layout.recipe_list, parent, false);
Log.d("follower","hi");
return new MyViewHolder(itemView);
}
#Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
final int i=position;
Log.d("follower","hi");
List dialog = DialogList.get(i);
Log.d("follower",dialog.toString());
String dishid = dialog.get(0).toString();
final String dishname = dialog.get(1).toString();
//byte[] dishimage = Base64.decode(dialog.get(2).toString(), Base64.DEFAULT);
String dishimage=dialog.get(2).toString();
String rating=dialog.get(3).toString();
holder.dishnames.setText(dishname);
holder.dishratings.setRating(Float.parseFloat(rating));
holder.mLoader.DisplayImage(dishimage.replaceAll(" ", "%20"),holder.dishimages);
}
#Override
public int getItemCount() {
return DialogList.size();
}}
Recyclerview
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(mLayoutManager);
xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
tools:context="mealplanner.com.main.mealplanner.MainActivity"
>
<android.support.v7.widget.RecyclerView
android:id="#+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:scrollbars="vertical" />
</LinearLayout>
Row List
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
card_view:cardUseCompatPadding="true"
card_view:cardElevation="4dp"
card_view:cardCornerRadius="3dp"
android:id="#+id/cv">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:id="#+id/dishimage"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginRight="6dip"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_margin="10dp"
android:src="#drawable/portraitlanding"
/>
<TextView
android:id="#+id/dishname"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_toRightOf="#+id/dishimage"
android:textColor="#000000"
android:textSize="20dp"
android:layout_gravity="center"
android:text="Andrew" />
<RatingBar
android:id="#+id/dishrating"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
style="?android:attr/ratingBarStyleSmall"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.1"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:layout_below="#+id/dishname"
android:layout_toRightOf="#+id/dishimage"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
DishesAdapter constructor is being called. I am getting follower1 log along with the list of items.

Android RecyclerView and CardView LayoutManager always crash in Fragment

my app always crash,i try to access a fragment that displays a cardview using RecyclerView.
Here is my Fragment
public class Fragmentone extends Fragment {
private RecyclerView recyclerView;
private List<TestBean> listItem;
private RecyclerAdapter adapter;
public Fragmentone() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_fragmentone, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
initData();
adapter = new RecyclerAdapter(listItem,getActivity());
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setHasFixedSize(true);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(adapter);
return view;
}
private void initData() {
listItem = new ArrayList<>();
listItem.add(new TestBean("佛山傻逼酒店","二月17号","二月18号","600","已付款"));
}
}
and this is my adapter
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.ListViewHolder> {
private List<TestBean> listitem;
private Context context;
public RecyclerAdapter(List<TestBean> listitem, Context context) {
this.listitem = listitem;
this.context = context;
}
#Override
public ListViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(context).inflate(R.layout.card_item, viewGroup, false);
ListViewHolder listViewHolder = new ListViewHolder(v);
return listViewHolder;
}
#Override
public void onBindViewHolder(ListViewHolder holder, int i) {
holder.tv_roomfee.setText(listitem.get(i).getRoomfee());
holder.tv_hotelname.setText(listitem.get(i).getHotelname());
holder.tv_liststate.setText(listitem.get(i).getListstate());
holder.tv_checkindate.setText(listitem.get(i).getCheckindate());
holder.tv_lastcheckindate.setText(listitem.get(i).getLastcheckindate());
holder.btn_paynow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
holder.btn_cancellist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
#Override
public int getItemCount() {
return listitem.size();
}
public class ListViewHolder extends RecyclerView.ViewHolder {
CardView id_cardview;
TextView tv_roomfee;
TextView tv_liststate;
TextView tv_hotelname;
TextView tv_checkindate;
TextView tv_lastcheckindate;
Button btn_paynow;
Button btn_cancellist;
public ListViewHolder(final View itemView) {
super(itemView);
id_cardview = (CardView) itemView.findViewById(R.id.id_cardview);
tv_roomfee = (TextView) itemView.findViewById(R.id.tv_roomfee);
tv_liststate = (TextView) itemView.findViewById(R.id.tv_liststate);
tv_hotelname = (TextView) itemView.findViewById(R.id.tv_hotelname);
tv_checkindate = (TextView) itemView.findViewById(R.id.tv_checkindate);
tv_lastcheckindate = (TextView) itemView.findViewById(R.id.tv_lastcheckindate);
btn_paynow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
btn_cancellist.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
}
}
}
and this is my cardview's xml
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp">
<android.support.v7.widget.CardView
android:id="#+id/id_cardview"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:elevation="8dp"
app:cardCornerRadius="8dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="#+id/stv_hotelname"
android:layout_width="wrap_content"
android:layout_height="50dp">
<ImageView
android:id="#+id/iv_hotelicon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#mipmap/ic_hotelicon" />
<TextView
android:id="#+id/tv_hotelname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/iv_hotelicon"
android:text="佛山精神酒店"
android:textSize="18sp" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlay_roomfee"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp">
<TextView
android:id="#+id/stv_roomfee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="¥"
android:textColor="#F6070C"
android:textSize="18dp" />
<TextView
android:id="#+id/tv_roomfee"
android:layout_toRightOf="#+id/stv_roomfee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#F6070C"
android:text="400"
/>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/rlay_roomfee"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp">
<TextView
android:id="#+id/tv_list"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/tv_liststate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#F6070C"
android:text="待支付"/>
</RelativeLayout>
<RelativeLayout
android:layout_below="#+id/stv_hotelname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="40dp"
>
<TextView
android:id="#+id/stv_checkindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="入住时间:"/>
<TextView
android:id="#+id/tv_checkindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#id/stv_checkindate"
android:text="1月10号"/>
<TextView
android:id="#+id/stv_lastcheckindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/stv_checkindate"
android:text="最晚入住时间:"/>
<TextView
android:id="#+id/tv_lastcheckindate"
android:layout_below="#+id/tv_checkindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/stv_lastcheckindate"
android:text="1月11号"/>
</RelativeLayout>
<RelativeLayout
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/btn_cancellist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="取消订单"/>
<Button
android:id="#+id/btn_paynow"
android:layout_toRightOf="#+id/btn_cancellist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="立即支付"/>
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
when i note
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
it doesn't crash ,but the cardview does'show

Categories

Resources