My problem is probably very simple, but I can't find out why the below
code fails (at the "arrayAdapter1.clear()".
Background : My class extends Activity (which is started from a
buttonclick in the Main activity) and displays 2 buttons and a
listview. When onCreate, the listview is filled with countries. This
works.
When pressing one of the buttons I want to modify (clear) the list.
Here the program stops unexpectedly. Any idea?
public class AlbumListView extends Activity
{
static final String[] COUNTRIES = new String[] {"Afghanistan",
"Albania", ... "Zimbabwe"};
public ListView list11;
public ArrayAdapter<String> arrayAdapter1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.album_list);
arrayAdapter1 = new ArrayAdapter<String>
(this,R.layout.album_row, COUNTRIES);
list11 = (ListView)findViewById(R.id.list);
list11.setTextFilterEnabled(true);
list11.setAdapter(arrayAdapter1);
final Button confirm_button = (Button) findViewById
(R.id.confirm);
final Button disconnect_button = (Button) findViewById
(R.id.disconnect);
disconnect_button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
arrayAdapter1.clear(); // FAILS
HERE !
list11.setAdapter(arrayAdapter1);
}
});
confirm_button.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
// Perform action on clicks
Bundle bundle = new Bundle();
Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();
}
});
}
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---