He conseguido poner en práctica una gran vista de lista que encontré aquí http://www.learn-android.com/2011/11/22/lots-of-lists-custom-adapter/comment-page-1/ pero me parece que no puede agregar un OnClickListener Sólo quiero ser capaz de hacer una acción al hacer clic en la fila, con los datos que la fila contiene por supuesto alguna idea? graciasAdición de una OnClickListener a vista de lista (androide)
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.liste);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
// Setup the list view
final ListView prestListView = (ListView) findViewById(R.id.list);
final prestationAdapterEco prestationAdapterEco = new prestationAdapterEco(this, R.layout.prestation);
prestListView.setAdapter(prestationAdapterEco);
// Populate the list, through the adapter
for(final prestationEco entry : getPrestations()) {
prestationAdapterEco.add(entry);
}
prestListView.setClickable(true);
prestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
Object o = prestListView.getItemAtPosition(position);
String str=(String)o;//As you are using Default String Adapter
Toast.makeText(getApplicationContext(),str,Toast.LENGTH_SHORT).show();
}
});
}
¿Qué está fallando, o cómo está fallando? ¿Ves comportamiento como http://stackoverflow.com/questions/4579754/listview-no-longer-reacts-to-onclick-after-a-call-to-setselection? –
bloquea la aplicación cuando la ejecuto –
carga la lista pero se cuelga cuando selecciono un artículo –