Note that there are some explanatory texts on larger screens.

plurals
  1. POHow create a new intent for each line of a list?
    primarykey
    data
    text
    <p>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.</p> <pre><code>public class Listview extends Activity { static ListView listView; static public class BackgroundWorker extends AsyncTask&lt;Void, Person, Void&gt; { @SuppressWarnings("unchecked") @Override protected void onPreExecute () { // Prima di iniziare a inserire gli elementi svuotiamo l'adapter ( ( ArrayAdapter&lt;Person&gt; ) 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 &lt; 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&lt;Person&gt; ) 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&lt;Person&gt;() ) ); listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; 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(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload