首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >CustomView中的2改造

CustomView中的2改造
EN

Stack Overflow用户
提问于 2017-07-29 06:55:54
回答 1查看 356关注 0票数 0

在我的代码中,我使用了一个使用Retrofit2和自定义回收视图的互联网示例,但是我决定从4.1.2版本开始在安卓中使用这个应用程序,这样回收视图就不会在那里工作了。那么,是否有可能将自定义回收视图更改为自定义列表视图?

Lista_productos.java

代码语言:javascript
复制
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

代码语言:javascript
复制
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:每一行的元素

代码语言:javascript
复制
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

代码语言:javascript
复制
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

代码语言:javascript
复制
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;
}
}
EN

回答 1

Stack Overflow用户

发布于 2017-07-30 07:24:25

看起来RecyclerView确实适用于Android4.1.2。请参阅这个问题的公认答案:Would recyclerview work on an android device with Jellybean?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45386349

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档