Search code examples
androidgoogle-cloud-firestoreandroid-recyclerviewonitemclicklistener

Call intent on Recycler View


this is my Recycler Adapter.i want make a call when clicking call button. i don't know what to do. please help me i added call button on holder. and after that i don't know anything. this application making for blood bank in my locality. so please help me immediately.

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.firestore.FirestoreRecyclerAdapter;
import com.firebase.ui.firestore.FirestoreRecyclerOptions;
import com.google.firebase.database.snapshot.Index;
import com.google.firebase.firestore.DocumentSnapshot;

public class NoteAdapter extends FirestoreRecyclerAdapter<Note, NoteAdapter.NoteHolder> {

    ListActivity listActivity;
    Context context;
    public NoteAdapter(@NonNull FirestoreRecyclerOptions<Note> options) {
        super (options);
    }

    @Override
    protected void onBindViewHolder(@NonNull NoteHolder holder, final int position, @NonNull final Note model) {
        holder.name.setText (model.getName ());
        holder.place.setText (model.getPlace ());
        holder.location.setText (model.getMuncipality ());
        holder.blood.setText (model.getBloodgroup ());
        holder.number.setText (model.getNumber ());

    }

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

    static class NoteHolder extends RecyclerView.ViewHolder{
        ListActivity listActivity;
        Context context;
        TextView name;
        TextView place;
        TextView blood;
        TextView location;
        TextView number;
        Button call;

        public NoteHolder(@NonNull View itemView) {
            super (itemView);
            name=itemView.findViewById (R.id.Name);
            place=itemView.findViewById (R.id.Place);
            blood=itemView.findViewById (R.id.Blood_group);
            location=itemView.findViewById (R.id.Muncipality);
            number=itemView.findViewById (R.id.mobileNumber);
            call=itemView.findViewById (R.id.call);

        }

    }
}

Solution

  • You can also directly pass the number like this.

    Intent intent = new Intent(Intent.ACTION_CALL);
    intent.setData(Uri.parse("tel:" + model.getNumber());
    context.startActivity(intent);