21.04.2014 Views

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

Curso-Android-Desarrollo-de-Aplicaciones-Móviles

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CURSO ANDROID<br />

39<br />

Mostrar datos siguiendo el diseño<br />

La función auxiliar setData <strong>de</strong> la guía anterior se ve drásticamente reducida ya que ahora utilizamos<br />

nuestro adaptador y por tener una activity que hereda <strong>de</strong> ListActivity la asignación al ListView lo hacemos<br />

con setListAdapter.<br />

private void setData(){<br />

this.setListAdapter(new MyAdapter(this, R.layout.row, 0,<br />

appState.getData()));<br />

}<br />

Esta herencia <strong>de</strong> nuestra Activity, también nos permite colocar la función onListItemClick para especificar<br />

la operación a realizar cuando el usuario presiona click sobre un elemento. Validamos la opción<br />

seleccionada por el usuario guardada en la clase <strong>de</strong> aplicación y <strong>de</strong>pendiendo <strong>de</strong>l caso levantamos un<br />

intent diferente.<br />

protected void onListItemClick(ListView l, View v, int position, long id) {<br />

super.onListItemClick(l, v, position, id);<br />

Intent nextActivity = null;<br />

if (appState.getSelectedOption() == APP_VIEW) {<br />

nextActivity = new Intent(this, ShowElement.class);<br />

nextActivity.putExtra(POSITION_KEY, position);<br />

} else {<br />

LinkedList data = appState.getData();<br />

nextActivity = new Intent(Intent.ACTION_VIEW,<br />

Uri.parse(data.get(position).getLink()));<br />

}<br />

this.startActivity(nextActivity);<br />

}<br />

Permanece la variable <strong>de</strong> instancia para el diálogo <strong>de</strong> progreso y el manejador es ligeramente distinto<br />

porque ya no recibe los datos a través <strong>de</strong>l mensaje.<br />

private final Handler progressHandler = new Handler() {

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!