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
0 Response to "Load ListView contents from XML resources"
Posting Komentar