listview : without repeating code

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

listview : without repeating code

Postby gsk » Thu Nov 13, 2008 7:15 am

hi ...
I am facing the simple problem with listview code.

I Override the OnCreate() like following:

@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.xxxx);

setListAdapter(new ArrayAdapter<String> this , android.R.layout.simple_list_item_multiple_choice,listitems));


final ListView listView = getListView();

listView.setFocusable(false);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

}


and its working fine..
I done some modifications on list (ie . removing few items from the list ) and i need to show the list(after modification) in the same screen as a listview.

I can able to get the list as a listview . by repeating the code like following


setListAdapter(new ArrayAdapter<String> this , android.R.layout.simple_list_item_multiple_choice,newlist));


final ListView listView = getListView();

listView.setFocusable(false);
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);


and its working fine ....(i got what i want )

but I dont want to repeat the setListAdapter() .....
is there any other way to do this ...

please help..
gsk
Junior Developer
Junior Developer
 
Posts: 10
Joined: Wed Nov 05, 2008 11:12 am

Top

Postby rmanromga » Fri Nov 14, 2008 4:29 am

If the contents of the list are bound to an adapter and you delete some items by creating a new list, i don't think that there is any orther way to update your ListView without calling setAdapter() again... unless someone else has another idea...

cheers,
--D
rmanromga
Developer
Developer
 
Posts: 43
Joined: Thu Dec 20, 2007 6:21 am
Location: Baltimore, MD USA

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests