Necesito controlar la pulsación sobre el Listview personalizado para que realice una operación dependiendo el que se pulsa. Ya tengo el OnItemClickListener.
Pero, como puedo pasar los datos contenidos en el Item hacia otra Activity
Les dejo el código principal
public class Noticias extends AppCompatActivity {
ArrayList<Product> arrayList;
ListView lv;
ProgressDialog pdialog = null;
Context context = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noticias);
android:setTitle("Noticias");
arrayList = new ArrayList<>();
lv = (ListView) findViewById(R.id.listView);
context = this;
runOnUiThread(new Runnable() {
@Override
public void run() {
pdialog = ProgressDialog.show(context, "", "Buscando Noticias...", true);
new ReadJSON().execute("http://xxxxxxx/xxxxx/xxxxxx.php");
}
});
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
Toast.makeText(getApplicationContext(), "Click en la posición " + position, Toast.LENGTH_SHORT).show();
}
});
}
class ReadJSON extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... params) {
return readURL(params[0]);
}
@Override
protected void onPostExecute(String content) {
pdialog.dismiss();
try {
JSONArray jsonarray = new JSONArray(content);
for(int i =0;i<jsonarray.length(); i++){
JSONObject productObject = jsonarray.getJSONObject(i);
arrayList.add(new Product(
productObject.getString("nombre"),
productObject.getString("contenido"),
productObject.getString("extra1")
));
}
} catch (JSONException e) {
e.printStackTrace();
}
CustomListAdapter adapter = new CustomListAdapter(
getApplicationContext(), R.layout.custom_list_layout, arrayList
);
lv.setAdapter(adapter);
}
}
private static String readURL(String theUrl) {
StringBuilder content = new StringBuilder();
try {
// create a url object
URL url = new URL(theUrl);
// create a urlconnection object
URLConnection urlConnection = url.openConnection();
// wrap the urlconnection in a bufferedreader
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
String line;
// read from the urlconnection via the bufferedreader
while ((line = bufferedReader.readLine()) != null) {
content.append(line + "\n");
}
bufferedReader.close();
} catch (Exception e) {
e.printStackTrace();
}
return content.toString();
}
}
Llevo varios días buscando y solo encuentro información con Arrays creados localmente
Este es el codigo de la nueva actividad en donde recibo los datos del Item
public class Noticia extends AppCompatActivity {
TextView tvname,tvcontenido;
ImageView imgview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_noticia);
Intent intent = getIntent();
String nombre = intent.getStringExtra("nombre");
String contenido = intent.getStringExtra("contenido");
String extra1 = intent.getStringExtra("extra1");
tvname = (TextView)findViewById(R.id.tvname);
tvcontenido = (TextView)findViewById(R.id.tvcontenido);
imgview = (ImageView)findViewById(R.id.imgview);
tvname.setText(nombre);
tvcontenido.setText(contenido);
imgview.setImageURI(Uri.parse(extra1));
}
}
Pero solo me muestra los campos con texto... la Imagen no la muestra