当我单击RecyclerView时,我想从Firebase中提取数据。我想将我从数据库中提取的数据传输到微调器。但是“ ViewGroup.getContext()'对空对象进行引用”错误。我想将数据传输到Rooms数组并将其添加到微调器。
public class ProductsNewAdapter extends RecyclerView.Adapter<ProductsNewAdapter.ProductViewHolder> {
List<String> Rooms = new ArrayList<String>();
private Context context;
@Override
public void onBindViewHolder(final ProductViewHolder holder, final int position) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
selectedPosition=position;
notifyDataSetChanged();
DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
DatabaseReference refRooms = mDatabase.child("0").child("Rooms");
refRooms.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()){
Spinner spinner = (Spinner) v.findViewById(R.id.spinnerMain);
ViewGroup parent = null;
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.product_laylout_new, parent, false);
ProductViewHolder vh = new ProductViewHolder(view);
context = parent.getContext();
Intent i = new Intent(context.getApplicationContext(),ProductsNewAdapter.class);
context.startActivity(i);
// ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(Context, // android.R.layout.simple_spinner_item, Rooms);
//dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// spinner.setAdapter(dataAdapter);
String data = snapshot.getValue(String.class);
Rooms.add(data);
// addListenerOnSpinnerItemSelection();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});