0

In meinem Code verwende ich ein Internet-Beispiel, das mit Retrofit2 und benutzerdefinierten Recyclerview funktioniert, aber ich entscheide mich, diese Anwendung in Android ab Version 4.1.2 zu verwenden, damit die Recyclerview dort nicht funktioniert. Es gibt also eine Möglichkeit, die benutzerdefinierte Recycleransicht in eine benutzerdefinierte Listenansicht zu ändern.Nachrüstung 2 in einer CustomView

Lista_productos.java

public class Lista_productos extends AppCompatActivity { 

private RecyclerView recyclerView; 
private RecyclerView.LayoutManager layoutManager; 
private List<Elementos_fila_productos> elementos; 
private RecyclerviewAdapter adapter; 
private ApiInterface apiInterface; 

static LayoutInflater layoutInflater; 

static PopupWindow popupWindow; 

static TextView nombre_seleccionado; 

static FrameLayout frameLayout; 

static String cantidad_deseada; 

static char hola; 



@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.lista_productos); 


    recyclerView = (RecyclerView)findViewById(R.id.recyclerview_tablillas); 
    layoutManager = new LinearLayoutManager(this); 
    recyclerView.setLayoutManager(layoutManager); 
    recyclerView.setHasFixedSize(true); 


    if(getIntent().getExtras() != null){ 

     String type = getIntent().getExtras().getString("type"); 

     buscarInformacion(type); 
    } 

} 


public void buscarInformacion(String type){ 

    apiInterface = ApiClient.getApiClient().create(ApiInterface.class); 

    Call<List<Elementos_fila_productos>> call = apiInterface.getElementosInfo(type); 

    call.enqueue(new Callback<List<Elementos_fila_productos>>() { 
     @Override 
     public void onResponse(Call<List<Elementos_fila_productos>> call, Response<List<Elementos_fila_productos>> response) { 

      elementos = response.body(); 
      adapter = new RecyclerviewAdapter(elementos, Lista_productos.this); 
      recyclerView.setAdapter(adapter); 

     } 

     @Override 
     public void onFailure(Call<List<Elementos_fila_productos>> call, Throwable t) { 

      final AlertDialog.Builder builder = new AlertDialog.Builder(Lista_productos.this, R.style.Theme_AppCompat_Light_Dialog_Alert); 
      builder.setCancelable(true); 
      builder.setTitle("Error!"); 
      builder.setMessage("mensaje"); 
      builder.setIcon(R.drawable.ic_launcher); 

      builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { 
       @Override 
       public void onClick(DialogInterface dialog, int which) { 

       } 
      }); 


      final AlertDialog dialog = builder.create(); 
      dialog.show(); 




     } 
    }); 

} 

} 

ListaComprasAdapter.java

public class ListaComprasAdapter extends BaseAdapter { 

ArrayList<String> nombre; 
ArrayList<String> cantidad; 
ArrayList<String> precio; 
ArrayList<String> total; 

Context mContext; 

//constructor 
public ListaComprasAdapter(Context mContext, ArrayList<String> nombre, ArrayList<String> cantidad, ArrayList<String> precio, ArrayList<String> total) { 
    this.mContext = mContext; 
    this.nombre = nombre; 
    this.cantidad = cantidad; 
    this.precio = precio; 
    this.total = total; 
} 

public int getCount() { 
    return nombre.size(); 
} 

public Object getItem(int arg0) { 
    return null; 
} 

public long getItemId(int position) { 
    return position; 
} 

public View getView(int position, View arg1, ViewGroup viewGroup) { 
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View row = inflater.inflate(R.layout.custom_lista_de_compras, viewGroup, false); 

    TextView Nombre = (TextView) row.findViewById(R.id.nombre_del_producto); 
    TextView Cantidad = (TextView) row.findViewById(R.id.cantidad); 
    TextView Precio = (TextView) row.findViewById(R.id.precio); 
    TextView Total = (TextView) row.findViewById(R.id.precio_total_producto); 

    Nombre.setText(nombre.get(position)); 
    Cantidad.setText(cantidad.get(position)); 
    Precio.setText(precio.get(position)); 
    Total.setText(total.get(position)); 


    return row; 
} 

} 

Elementos_fila_productos.java: die Elemente jeder Zeile

public class Elementos_fila_productos { 

@SerializedName("ID") 
private String ID; 

@SerializedName("Caracteristicas") 
private String Caracteristicas; 

@SerializedName("Precio") 
private int Precio; 

@SerializedName("Grosor") 
private String Grosor; 

@SerializedName("Disponibles") 
private int Disponible; 

@SerializedName("Imagen") 
private String Imagen; 



public String getGrosor() { 
    return Grosor; 
} 

public String getID() { 
    return ID; 
} 

public String getCaracteristicas() { 
    return Caracteristicas; 
} 

public int getPrecio() { 
    return Precio; 
} 

public int getDisponible() { 
    return Disponible; 
} 

public String getImagen() { 
    return Imagen; 
} 
} 

ApiInterface.java

public interface ApiInterface { 

@GET("tablillas2.php") 


    //revisar en el caso de que no funcione 
Call<List<Elementos_fila_productos>> getElementosInfo(@Query("item_type") String item_type); 
} 

ApiClient.java

public class ApiClient { 

public static final String Base_Url = "http://creadorjuancarloscfapptablilla.esy.es/appTablillas/"; 

public static Retrofit retrofit; 


public static Retrofit getApiClient(){ 

    if (retrofit==null){ 

     retrofit = new Retrofit.Builder().baseUrl(Base_Url).addConverterFactory(GsonConverterFactory.create()).build(); 
    } 

    return retrofit; 
} 
} 

Antwort

Verwandte Themen