Hide and Show ImageView in a List

0

Hello People How can I hide and show an image in a list with adapter. The idea is that in my list when I press a line, I have a menu to choose finished, the image should show in that line of the list that Choose ... I try the brutes but only show it to me in the last line. please help There is my codes

My adapter class

public class Adaptergeneric extends BaseAdapter {
TextView txtDescart;
TextView txtrenglon;
TextView txtdespacho;
ImageView ImgStock;
Context context;
JSONArray oJS;

LayoutInflater inflater;

public Adaptergeneric(Context context, JSONArray pJS) {
    this.context = context;
    this.oJS = pJS;
}


@Override
public int getCount() {
    return oJS.length();
}

@Override
public Object getItem(int i) {
    try {
        return oJS.getJSONObject(i);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;
}


@Override
public long getItemId(int i) {
    return 0;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {

    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.item_generic_pedidos, viewGroup, false);


    txtrenglon = (TextView) itemView.findViewById(R.id.renglon);
    txtDescart = (TextView) itemView.findViewById(R.id.descart);
    txtdespacho = (TextView) itemView.findViewById(R.id.destino);
    ImgStock = (ImageView) itemView.findViewById(R.id.imgEstado);

    try {
        txtDescart.setText(oJS.getJSONObject(i).getString("tareas"));
        txtrenglon.setText(oJS.getJSONObject(i).getString("renglon"));
        txtdespacho.setText(oJS.getJSONObject(i).getString("destino"));

        } catch (JSONException e) {
        e.printStackTrace();
    }
    return itemView;
}
public void function() {
    ImgStock.setVisibility(View.VISIBLE);
}

}  the class where my list is

 private class GetPedidos extends AsyncTask<String, String, String> {
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Operaciones.this);
        pDialog.setMessage("Cargando...");
        pDialog.setCancelable(false);
       pDialog.show();

    }

    @Override
    protected String doInBackground(String... strings) {

        final String url = "http://danbijann.freeiz.com/consulta.json";
        HttpHandler sh = new HttpHandler();
        JSONObject jsonStr = sh.makeServiceCall(url);
        try {
            contacts = jsonStr.getJSONArray("PEDIDOS");
            } catch (final JSONException e) {
            Log.e(TAG, "Json parsing error: " + e.getMessage());
        }
        return null;
    }

    @Override
    protected void onPostExecute(String result) {

        super.onPostExecute(result);
        if (pDialog.isShowing())
            pDialog.dismiss();
        pedidosAdap = new Adaptergeneric(Operaciones.this, contacts);
        listaPedidos.setAdapter(pedidosAdap);
        registerForContextMenu(listaPedidos);
    }
        }
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    MenuInflater inflate = getMenuInflater();
    if (v.getId() == R.id.listaPedidos) {

        inflate.inflate(R.menu.estado, menu);
    }
}
public boolean onContextItemSelected(final MenuItem item) {

    final Context context = this;
    AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
        case R.id.mnu_estado:
            pedidosAdap.function();
            return super.onContextItemSelected(item);

    }
    return false;

}

Sometimes the image appears in the last line

    
asked by user62207 27.07.2018 в 20:24
source

0 answers