Reputation: 115
I have this list ... I should put a check box as the last element (where the word "notification") ... I do not know how to do .. because each element has its own icon ... but the last I've got to put a checkbox ....
enter code here
public class Listview extends Activity {
protected static final Intent CopyOfListview = null;
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",null, R.drawable.freccetta ) };
Person[] people1 = {new Person( " Visualizzazione", null, R.drawable.freccetta )};
Person[] people2= { new Person( " Notifiche", null, R.drawable.freccetta)};
// 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 ( final Bundle savedInstanceState ) {
super.onCreate( savedInstanceState );
requestWindowFeature(Window.FEATURE_NO_TITLE);
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);
switch(position) {
case 0:
Activity_privacy();
// startActivity(CopyOfListview);
//onCreate1(savedInstanceState);
// setContentView(R.layout.main1);
break;
case 1:
setContentView(R.layout.main2);
break;
case 2:
setContentView(R.layout.main3);
}
}
});
new BackgroundWorker().execute();
}
protected void Activity_privacy()
{
Intent i = new Intent(this, CopyOfListview.class);
startActivity(i);
}
}
Upvotes: 1
Views: 180
Reputation: 3903
Have your PersonAdapter class return the button view when getView is called for the last element of the list. Be sure that getCount returns the correct size when you do this.
You may also benefit from having the adapter take a collection of view factories instead of List<Person>.
Upvotes: 0
Reputation: 30845
Is there some reason adding a footer view wouldn't work?
If for some reason that's not an acceptable solution, the only other thing I can think of is to create a custom class that implements the Adapter interface. It will have to return two different view types (i.e. getViewTypeCount()
will return 2) and returns different views from getView()
based on the position you're requesting the view for.
Upvotes: 1