Buenas mi problema como el de muchos es el adaptador "E/RecyclerView: No adapter attached; skipping layout "
la idea es crear un nuevo campo en Firebase DB (que esta conectado y funciona a la perfección) es este el único problema que poseo!
Por muchos lados he buscado y el error es el mismo, que depronto esta vació al inicializarlo pero no encuentro el modo de inicializarlo ya con información para que me cree el espacio en Firebase.... la gran duda mía! es por que con el System.curentTimeMillis() puedo enviar el pedido a Firebase?
Me Urge ayuda por favor muchas gracias!!
ah y por cierto lo he sacado del siguiente vídeo: https://www.youtube.com/watch?v=nlQTN7vkc0c
adjunto mi código
`
public class Carrito extends AppCompatActivity {
RecyclerView recyclerView;
RecyclerView.LayoutManager layoutManager;
FirebaseDatabase database;
DatabaseReference pedido;
TextView txtTotalPrecio;
Button btn_pace;
List < Order > cart = new ArrayList<>();
CartAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carrito);
//Init Firebase
database = FirebaseDatabase.getInstance();
pedido = database.getReference("OrdenPedido") ;
//Init
recyclerView = (RecyclerView) findViewById(R.id.ListaCarrito);
recyclerView.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
txtTotalPrecio =(TextView) findViewById(R.id.total);
btn_pace =(Button)findViewById(R.id.btn_PlaceOrder);
btn_pace.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showAlertDialog();
}
});
LoadListFood();
}
private void showAlertDialog() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(Carrito.this);
alertDialog.setTitle("Ultimo Requisito");
alertDialog.setMessage("Ingresa tu Numero de celular");
final EditText edtPhone = new EditText(Carrito.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT
);
edtPhone.setLayoutParams(lp);
alertDialog.setView(edtPhone);
alertDialog.setIcon(R.drawable.ic_shopping_cart_black);
alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//envair a Firebase
Request request = new Request(
txtTotalPrecio.getText().toString(),
edtPhone.getText().toString(),
cart
);
pedido.child(String.valueOf(System.currentTimeMillis()))
.setValue(request);
//Delete cart
new Database(getBaseContext()).CleanToCart();
Toast.makeText(Carrito.this, "Gracias, Pedido Realizado", Toast.LENGTH_SHORT).show();
finish();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
alertDialog.show();
}
private void LoadListFood() {
cart = new Database(this).getCarts();
adapter = new CartAdapter(cart, this);
recyclerView.setAdapter(adapter);
//Precio final
int total = 0;
for (Order order:cart)
total += (Integer.parseInt(order.getPrecio()))*(Integer.parseInt(order.getCantidad()));
Locale locale = new Locale( "es", "CO");
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
txtTotalPrecio.setText(fmt.format(total));
}
}
`
y adjunto tambien la clase CartAdapter!
`
class CartViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txt_cart_name , txt_precio;
public ImageView img_cart_count;
private InflatedOnMenuItemClickListener inflatedOnMenuItemClickListener;
public void setTxt_cart_name(TextView txt_cart_name) {
this.txt_cart_name = txt_cart_name;
}
public CartViewHolder(@NonNull View itemView) {
super(itemView);
txt_cart_name = (TextView) itemView.findViewById(R.id.cart_item_name);
txt_precio = (TextView) itemView.findViewById(R.id.cart_item_price);
img_cart_count = (ImageView) itemView.findViewById(R.id.cart_item_count);
}
@Override
public void onClick(View view) {
}
}
public class CartAdapter extends RecyclerView.Adapter {
private List< Order > listData = new ArrayList<>();
private Context context;
public CartAdapter(List< Order > listData, Context context) {
this.listData = listData;
this.context = context;
}
@NonNull
@Override
public CartViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View ItemView = inflater.inflate(R.layout.cart_layout,parent,false);
return new CartViewHolder(ItemView);
}
@Override
public void onBindViewHolder(@NonNull CartViewHolder holder, int position) {
TextDrawable drawable = TextDrawable.builder()
.buildRound(""+listData.get(position).getCantidad(), Color.TRANSPARENT);
holder.img_cart_count.setImageDrawable(drawable);
Locale locale = new Locale( "es", "CO");
NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
int price = (Integer.parseInt(listData.get(position).getPrecio()))
*(Integer.parseInt(listData.get(position).getCantidad()));
holder.txt_precio.setText(fmt.format(price));
holder.txt_cart_name.setText(listData.get(position).getProductoNombre());
}
@Override
public int getItemCount() {
if (listData != null)
return listData.size();
return 0;
}
}
`