Skip to content
Advertisement

Getting Problem In RecycleView with TextInputEditText

I am a new Programmer, actually I was trying to make an app. I was trying to make an activity that uses RecyclerView to Show TextInputEditText with spinner and TextView. It means that I was trying to make an activity that uses Recyclerview and In the layout of Recycler View, I have used Text Input Edit Text and Spinner and TextView. I have put these three in a single layout. But the main problem that I facing is that when I launch my app with my code then it remains blank activity it is not showing TextInputEditText nor spinner and nor TextView.

So the conclusion is I want to show [TextInputEditText, Spinner and TextView] in RecyclerView But my code is returning Blank Activity.

Here is my code:-

It is my adapter class:-

public class SpecialHoursAdapter extends RecyclerView.Adapter<SpecialHoursAdapter.SpecialHourHolder> {


//    private ArrayList[] mDataSet;

    private List<SpecialHorusModal> modal = new ArrayList<>();

    private Context context;

    public SpecialHoursAdapter(Context context) {
        this.context = context;
        

    }

    @NonNull
    @Override
    public SpecialHourHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.special_hours_layout_card, parent, false);
        return new SpecialHourHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull SpecialHourHolder holder, int position) {


    }

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

    public static class SpecialHourHolder extends RecyclerView.ViewHolder {

        private TextInputEditText editText;
        private Spinner spinner;
        private TextView textView;

        public SpecialHourHolder(@NonNull View itemView) {
            super(itemView);

            editText = itemView.findViewById(R.id.special_hours_editor);
            spinner = itemView.findViewById(R.id.spinner_special_hours_date);
            textView = itemView.findViewById(R.id.time_picker_special_horus);


        }
    }


}

It is My MainActivity:-

public class SpecialHoursActivity extends AppCompatActivity {
    private RecyclerView containerRecyclerView;
    private RecyclerView.LayoutManager first, container;
    private SpecialHoursAdapter adapter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_special_horus);




        //     mainRecyclerView = findViewById(R.id.activity_special_horus_main_recyclerview);
        containerRecyclerView = findViewById(R.id.layout_container_recyclerview_special_hours);

        //    mainRecyclerView.setHasFixedSize(true);
        containerRecyclerView.setHasFixedSize(true);

        first = new LinearLayoutManager(this);
        container = new LinearLayoutManager(this);


//        mainRecyclerView.setLayoutManager(first);
        containerRecyclerView.setLayoutManager(container);
        containerRecyclerView.setAdapter(adapter);

    }

}

Here is my RecyclerView Layout:-

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


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

        <com.google.android.material.textfield.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <com.google.android.material.textfield.TextInputEditText
                android:id="@+id/special_hours_editor"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Enter Special Hours"
                android:inputType="text"
                android:maxLength="20" />

        </com.google.android.material.textfield.TextInputLayout>

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

            <Spinner
                android:id="@+id/spinner_special_hours_date"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <TextView
                android:id="@+id/time_picker_special_horus"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="end"
                android:gravity="end"
                android:text="00:00" />

        </LinearLayout>

    </LinearLayout>

</androidx.cardview.widget.CardView>

My Main Layout –

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_special_horus_main_recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:scrollbars="vertical">


    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:id="@+id/layout_container_recyclerview_special_hours"
        android:orientation="vertical"
        android:scrollbars="vertical">


    </androidx.recyclerview.widget.RecyclerView>

</RelativeLayout>

I have not used any modal class because I don’t know how to use it with Widgets.

Advertisement

Answer

you need to pass the data to your adapter

public SpecialHoursAdapter(Context context,List<SpecialHorusModal> data) {
    this.context = context;
    this.model=data; //it will show your recyclerview  
   
}

we could not show the Recyclerview with empty data

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement