Create /res/values/month.xml file
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="month">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</string-array>
</resources>
Modify onCreate() to create ArrayAdapter from resource.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myList = (ListView)findViewById(R.id.list);
ArrayAdapter<CharSequence> adapter
= ArrayAdapter.createFromResource(this,
R.array.month,
R.layout.mylistlayout);
myList.setAdapter(adapter);
}
Related:
- ListView with multiple choice
thank you for your help!
ReplyDeletebut I was struggled to find what is 'mylistlayout'
Now I know it's the XML file 'mylistlayout.xml' from your former subject 'ListView with your own layout' !!
Please, please, please! Be more explicit next time..!