Click here to Skip to main content
14,970,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my recyclerview class where i have electrician,plumber,welder etc as my recyclerview items.i want whenever user click on any of these items the respective data that is retrived from firebase should be shown in the next activity..

Java
package com.example.hp.dc_project;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/** * Created by HP on 20-07-2018. */public class RecyclerViewAdapter extends 
RecyclerView.Adapter<RecyclerViewAdapter.MyViewHolder>{

private Context mContext;
private List<category> mdata;

public RecyclerViewAdapter(Context context, List<category> mdata) {
    this.mContext = context;
    this.mdata = mdata;
}

@Override    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    View view;
    LayoutInflater mInflater = LayoutInflater.from(mContext);
    view = mInflater.inflate(R.layout.cardview_category,parent,false);
    return new MyViewHolder(view);
}

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

    holder.tv.setText(mdata.get(position).getName());
    holder.iv.setImageResource(mdata.get(position).getThumnail());
    holder.cardView.setOnClickListener(new View.OnClickListener() {
        @Override            public void onClick(View v) {
            Intent i = new Intent(mContext.getApplicationContext(),available_worker.class);
            mContext.startActivity(i);
        }
    });

}

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

public static class MyViewHolder extends RecyclerView.ViewHolder{

    TextView tv;
    ImageView iv;
    CardView cardView;

    public MyViewHolder(View itemView){
        super(itemView);

        tv = (TextView)itemView.findViewById(R.id.tv_category);
        iv = (ImageView)itemView.findViewById(R.id.iv_category);
        cardView = (CardView)itemView.findViewById(R.id.cardview);
    }
}
}


What I have tried:

this is the activity class where i want to display the listview containing the data that is retrieved from firebase after clicking on the recyclerview items..
Java
package com.example.hp.dc_project;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import java.util.ArrayList;

public class available_worker extends AppCompatActivity {
private ListView lv;
private FirebaseDatabase database;
private ArrayList<String>list;
private ArrayAdapter<String>adapter;
private Electrician elec;
//  adapter = new ArrayAdapter<Electrician>(this,R.layout.list_of_work    @Override    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_available_worker);
    lv = (ListView)findViewById(R.id.listView_workeravailable);
    elec = new Electrician();
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override            public void onItemClick(AdapterView<?>parent, View view, int position, long id) {
            Intent i = new Intent(available_worker.this,WorkerProfile.class);
            startActivity(i);
        }
    });
    list =new ArrayList<>();
    adapter = new ArrayAdapter<String>(this,R.layout.list_of_worker,R.id.employeeadd );
    database = FirebaseDatabase.getInstance();
    DatabaseReference rootref = database.getReference();
    DatabaseReference electricianref = rootref.child("Employee").child("Electrician");
    electricianref.addValueEventListener(new ValueEventListener() {
        @Override            public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot ds : dataSnapshot.getChildren()) {
                String fName = ds.child("Fname").getValue(String.class);
                String lName = ds.child("Lname").getValue(String.class);
                String address = ds.child("Address").getValue(String.class);
                list.add(fName);
                list.add(lName);
                list.add(address);
            }
        }

        @Override            public void onCancelled(@NonNull DatabaseError databaseError) {

        }
});
} }
Posted
Comments
David Crow 9-Aug-18 15:49pm
   
Okay, so what exactly is the issue? Have you used the debugger to step through the available_worker class?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900