Foros del Web » Programando para Internet » Android »

Problema listview click item

Estas en el tema de Problema listview click item en el foro de Android en Foros del Web. Hola, estoy tratando de que en un listview los items tengan diferente accion al precionarlos, esta accion depende de una variable "estado", pero el problema ...
  #1 (permalink)  
Antiguo 13/06/2015, 20:04
 
Fecha de Ingreso: octubre-2014
Mensajes: 7
Antigüedad: 9 años, 6 meses
Puntos: 0
Pregunta Problema listview click item

Hola, estoy tratando de que en un listview los items tengan diferente accion al precionarlos, esta accion depende de una variable "estado", pero el problema es que todos los items quedan con la misma accion, aqui el codigo:

Código:
 
 for(int i = 0; i < json.length(); i++){
                    JSONObject c = json.getJSONObject(i);
                    // Storing  JSON item in a Variable
                    String  codigo = c.getString(TAG_CODIGO);
                    String  asignatura = c.getString(TAG_NOMBRE);
                    int  estado  = c.getInt("estado");
                    final int maxhoras = c.getInt("maxhoras");
                    final String idprogramacion = c.getString("programacionid");

                    // Adding value HashMap key => value
                    HashMap<String, String> map = new HashMap<String, String>();
                    map.put(TAG_CODIGO, codigo);
                    map.put(TAG_NOMBRE, asignatura);

                    jsonlist.add(map);
                    list=(ListView)findViewById(R.id.lvclases);
                    ListAdapter adapter = new SimpleAdapter(Bienvenida.this, jsonlist,
                            R.layout.listview,
                            new String[] { TAG_CODIGO,TAG_NOMBRE, }, new int[] {
                            R.id.codigo, R.id.nombre,
                    });
                    list.setAdapter(adapter);
                    if(estado == 1) {
                        Log.e("estado", ""+estado);
                        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view,
                                                    int position, long id) {
                                Intent i = new Intent(Bienvenida.this, registroAsistencia.class);
                                i.putExtra("programacion",  idprogramacion);
                                i.putExtra("maxhoras",  maxhoras);
                                startActivity(i);
                                /*Toast toast1 = Toast.makeText(getApplicationContext(), "Correcto: el usuario existe", Toast.LENGTH_SHORT);
                                toast1.show();*/
                                //Toast.makeText(Bienvenida.this, "You Clicked at " + jsonlist.get(+position).get("asignatura"), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }else{
                        list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

                            @Override
                            public void onItemClick(AdapterView<?> parent, View view,
                                                    int position, long id) {
                                Toast.makeText(Bienvenida.this, "la clase aún no ha comenzado " + jsonlist.get(+position).get("asignatura"), Toast.LENGTH_SHORT).show();
                            }
                        });
                    }
                }
Me podrian ayudar con esto.
Muchas gracias

Etiquetas: json, listview
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:04.