I have to make a list and call an intent different for each line. Can someone tell me what to write in code? The toast for now only appears to indicate that I’m calling that line.
public class Listview extends Activity {
static ListView listView;
static public class BackgroundWorker extends AsyncTask<Void, Person, Void> {
@SuppressWarnings("unchecked")
@Override
protected void onPreExecute () {
// Prima di iniziare a inserire gli elementi svuotiamo l'adapter
( ( ArrayAdapter<Person> ) listView.getAdapter() ).clear();
super.onPreExecute();
}
@Override
protected Void doInBackground ( Void... params ) {
// Qui dentro si possono mettere le operazioni che potrebbero
// rallentare il caricamento della listview, come ad sempio il
// caricamento da db degli oggetti
Person[] people = { new Person( "Privacy", "", R.drawable.creep_1 ) };
Person[] people1 = {new Person( "Visualizzazione", "", R.drawable.creep_2 )};
Person[] people2= { new Person( "Notifiche", "", R.drawable.creep_3 )};
// riempimento casuale della lista delle persone
Random r = new Random();
for ( int i = 0; i < 1; i++ ) {
// Pubblichiamo il progresso
publishProgress( people);
publishProgress( people1);
publishProgress( people2);
}
return null;
}
@SuppressWarnings("unchecked")
@Override
protected void onProgressUpdate ( Person... values ) {
// Aggiungiamo il progresso pubblicato all'adapter
( ( ArrayAdapter<Person> ) listView.getAdapter() ).add( values[0] );
super.onProgressUpdate( values );
}
}
@Override
public void onCreate ( Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
setContentView( R.layout.main );
listView = ( ListView ) findViewById( R.id.personListView );
listView.setAdapter( new PersonAdapter( this, R.layout.row_item, new ArrayList<Person>() ) );
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Person p = (Person) parent.getItemAtPosition(position);
Toast.makeText(
view.getContext(),
"Click sulla riga " + p.getFullName(),
Toast.LENGTH_SHORT
).show();
}
});
new BackgroundWorker().execute();
}
}
You can use a
switchstatement depending on the ListView’spositionand call the Activity you want.