开发者

how to display a list in android

I have a String countries[].

now when i click a button then on the onClick event this abc array is filled.suppose it is filled with the name of 10 countries.These 10 countries should be visible as a list so that i can choose any 1 country among the list. but i am not able to show them as a list.

My programme crashes if i use the following code :

ListView list = (ListView)findViewById(R.id.ListView);

list.setAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, countries));

As countries is filled later on the click of a button.So initially the countries array is empty and as the onCreate() is executed first it crashes.

I found the examples on net where there is pre-defined array.so it works.My array is filled in a 开发者_开发百科onClick event.how can i display List at that moment???


Make list your member variable.

Move the setAdapter call inside your onClick()....That'll do.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜