Reputation: 17
final ListView lv= (ListView)findViewById(R.id.list);
String[] from = new String[] {"a", "b","c"};
int[] to = new int[] { R.id.textbutton , R.id.buttonlist, R.id.imgart};
that's my variable
n my code
List<HashMap<String, String>> fillMaps = new ArrayList<HashMap<String, String>>();
String[]ArrayStr = Func.split(resultString, "|*|");
for(int i = 0; i < ArrayStr.length; i++){
String[]AStr = Func.split(ArrayStr[i], "|**|");
HashMap<String, String> map = new HashMap<String, String>();
map.put("a", ArrayStr[i]);
map.put("b", AStr[1]);
fillMaps.add(map);
}
// fill in the grid_item layout
SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.list, from, to);
lv.setAdapter(adapter);
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
});
why it's still can't click? whats wrong with my code?
sorry i'm noob in android...
Upvotes: 0
Views: 3630
Reputation: 7207
Your class must to extend ListActivity and override
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
//do something
}
EDIT
` public class ListaFicheros extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_ficheros);
//....
initLista(auxFile.listFiles());
}
private void initLista(File[]archivos){
//....
ArrayAdapter<String> listaArchivos= new mArrayAdapter(this,R.layout.fila_list_fich,R.id.lista_fich_texto_fila, elemSinExt);
setListAdapter(listaArchivos);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
int IDFilaSeleccionada = position;
Intent intent = new Intent(ListaFicheros.this,InterfazLector.class);
intent.putExtra("PATH", paths.get(IDFilaSeleccionada));
intent.putExtra("NOMBRE", elementos.get(IDFilaSeleccionada));
DoVibration.OK((Vibrator) getSystemService(Context.VIBRATOR_SERVICE));
startActivityForResult(intent, ID);
}`
Upvotes: 1