Estoy intentado seleccionar un botón insertado en un ListView
y que a partir de ahí el botón tenga una acción al seleccionarlo.
Este es mi código:
Dónde debería llamar a mi método onClick??
class GetCorrectivos extends AsyncTask<String, Void, String> implements View.OnClickListener {
String status = null;
Activity context;
ListView lv;
Defino el botón:
Button fechaAtendido = findViewById(R.id.fechaAtendido);
public GetCorrectivos(Activity context, ListView lv) {
this.context = context;
this.lv = lv;
}
protected void onPreExecute() {
**fechaAtendido.setOnClickListener(this)** Esto me da errorr
}
protected String doInBackground(String... connUrl) {
HttpURLConnection conn = null;
BufferedReader reader;
try {
final URL url = new URL(connUrl[0]);
conn = (HttpURLConnection) url.openConnection();
conn.addRequestProperty("Content-Type", "application/json; charset=utf-8");
conn.setRequestMethod("GET");
int result = conn.getResponseCode();
if (result == 200) {
InputStream in = new BufferedInputStream(conn.getInputStream());
reader = new BufferedReader(new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
status = line;
}
}
} catch (Exception e) {
}
return status;
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
if (result != null) {
try {
ArrayList<String> stringArrayList = new ArrayList<String>();
JSONArray jsonArray = new JSONArray(result);
for (int i = 0; i < jsonArray.length(); i++) {
// las variables
BrandList.add(itemList);
}
adapter = new SimpleAdapter(EquipoCorrectivo.this, BrandList, R.layout.item_correctivo, new String[] { "ID_CORRECTIVO", "ID_OT_EQUIPO", "FECHA_CORRECTIVO", "ATENDIDO", "FECHA_ATENDIDO", "REALIZADO", "FECHA_REALIZADO", "ZONA_PRODUCCION", "UBICACION", "DESCRIPCION", "SOLUCION"}, new int[]{R.id.idCorrectivo, R.id.idOTEq, R.id.fechaCorrectivo, R.id.atendido, R.id.fechaAtendido, R.id.realizado, R.id.fechaRealizado, R.id.zonaProd, R.id.ubica, R.id.descrip, R.id.solu});
((AdapterView<ListAdapter>) lv).setAdapter(adapter);
// adapter.notifyDataSetChanged();
// lv.invalidate();
// lv.requestLayout();
// lv.forceLayout();
if (adapter.isEmpty()) {
Toast.makeText(EquipoCorrectivo.this, "vacío", Toast.LENGTH_SHORT).show();
}
} catch (Exception ex) {
ex.printStackTrace();
}
} else {
Toast.makeText(EquipoCorrectivo.this, "Por favor active la conexión VPN", Toast.LENGTH_SHORT).show();
}
}
He intentado llamar aquí al método onClick pero no hay manera
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.fechaAtendido:
Aquí intento que el botón haga algo: Toast.makeText(EquipoCorrectivo.this, "mprueba", Toast.LENGTH_SHORT).show(); } } }
Alguien me podría echar una mano? No consigo que mi botón tenga una acción cuando lo selecciono