0

I want to create a recipe application, I the user to add the ingredients by creating only one Edit text, and every time the user press enter I want to show the item above the Edit text horizontally. user also can edit the item for example delete it.

I tried to create a recycler view :

<LinearLayout 
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:id="@+id/line1">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Ingrediants:"
    android:textSize="20dp"
    android:id="@+id/textviewtest"/>

<androidx.recyclerview.widget.RecyclerView
    android:layout_marginTop="23dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/recycletextitme"
    android:orientation="horizontal"
    />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:hint="exe:3 tomatoes..."
    android:singleLine="true"
    android:id="@+id/edititem"
    />

with adaper

    public class RecycleIngAdapter extends RecyclerView.Adapter<RecycleIngAdapter.IngHolder>   {

String sitme;
Context context;

public RecycleIngAdapter ( String sitme , Context context){
    this.context = context ;
    this.sitme = sitme;
}


@NonNull
@Override
public IngHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item,parent,false);
    //holder will take the info put it in the item layout
    IngHolder holder = new IngHolder(view);
    return holder;
}

@Override
public void onBindViewHolder(@NonNull IngHolder holder, int position) {
    holder.item.setText(sitme);
}

@Override
public int getItemCount() {
    return 0 ;
}


///class holder

class IngHolder extends RecyclerView.ViewHolder {

TextView item;

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

    item = (TextView) itemView.findViewById(R.id.textitem);
    itemView.findViewById(R.id.bottomdelet).setOnClickListener(view ->{

    });


}
}//end holder class

}

like this : enter image description here

I tried also to use the text watcher but it doesn't work :(

0 Answers0