0

I have a problem with my RecyclerView. The problem is, the word "Pending" is not located at the right of the RecyclerView. As I'm not able to post the image due to my reputation. Below I give the link of my current RecyclerView looks like.

https://scontent.fkul14-1.fna.fbcdn.net/v/t1.0-9/60160733_10216106491068205_5066642184581677056_n.jpg?_nc_cat=107&_nc_ht=scontent.fkul14-1.fna&oh=0a839d9c678868a4fd5bd814754e4f66&oe=5D598369

Then, below is my current XML code.

suggestion_list.xml

<FrameLayout 
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="left"
                android:text="Name"
                android:textColor="@color/colorAccent"
                android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/tvStatus"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:gravity="right"
                android:text="Pending"
                android:textColor="#F50808" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvName"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Name"
                android:textColor="@color/colorAccent" />
        </TableRow>

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="05dp"
            android:layout_marginRight="20dp">

            <TextView
                android:id="@+id/tvMonth"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Month"
                android:textColor="@color/colorAccent" />
            </TableRow>
    </LinearLayout>
</FrameLayout>

activity_my_history_list.xml

<LinearLayout 
     xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:id="@+id/haha"
     android:layout_height="match_parent"
     android:orientation="vertical"
     tools:context=".MyHistoryList">

<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:maxLines="1"
    android:clickable="false"
    android:focusable="false"
    android:longClickable="false"
    android:textStyle="bold"
    android:textSize="18sp"
    android:textColor="#FFFFFF" />

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recylcerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

UserAdapter.java

public class UserAdapter extends RecyclerView.Adapter<UserAdapter.ProductViewHolder> {

private Context mCtx;
private List<User> userList;
private View.OnClickListener mClickListener;

public UserAdapter(Context mCtx, List<User> userList) {
    this.mCtx = mCtx;
    this.userList = userList;
}

public void setClickListener(View.OnClickListener callback) {
    mClickListener = callback;
}

@Override
public ProductViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    LayoutInflater inflater = LayoutInflater.from(mCtx);
    View view = inflater.inflate(R.layout.suggestion_list, null);

    RecyclerView.ViewHolder holder = new ProductViewHolder(view);
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mClickListener.onClick(view);
        }
    });

    return new ProductViewHolder(view);
}

@Override
public void onBindViewHolder(ProductViewHolder holder, int position) {
    User user = userList.get(position);

        holder.tvTitle.setText(user.getTitle());
        holder.tvStatus.setText(user.getStatus());
        holder.tvName.setText(user.getName());
        holder.tvMonth.setText(user.getMonth());
        holder.id = user.getId();
}

@Override
public int getItemCount() {
    return userList.size();
}

class ProductViewHolder extends RecyclerView.ViewHolder {

    TextView tvTitle, tvName, tvMonth, tvStatus;
    int id;

    public ProductViewHolder(View itemView) {
        super(itemView);
        tvTitle = itemView.findViewById(R.id.tvTitle);
        tvName = itemView.findViewById(R.id.tvName);
        tvMonth = itemView.findViewById(R.id.tvMonth);
        tvStatus = itemView.findViewById(R.id.tvStatus);
    }
}

}

Thus, I want the word "Pending" is always at right. What is the problem actually? Any suggestion?

  • Please post the code in your `RecyclerView.Adapter` where you inflate that layout; likely the `onCreateViewHolder()` method. – Mike M. May 13 '19 at 02:06
  • @MikeM. Already edited. –  May 13 '19 at 02:11
  • You need to pass the `parent` parameter in the `inflate()` call. Change it to `inflater.inflate(R.layout.suggestion_list, parent, false)`. Also, ``s are generally only used inside a ``. And, when you use weights on `TableRow`/`LinearLayout` children, you want to set the corresponding dimension to `0dp`; i.e., change the `layout_width`s on those ``s to `0dp`. – Mike M. May 13 '19 at 02:12
  • 1
    @MikeM. Work perfectly!! Thanks mate! –  May 13 '19 at 02:15

0 Answers0