Using string arrays to fill a list view in Android
I am new to Android and Java development. I am trying to fill a list view using a string array. I continue to get an error - The constructor ArrayAdapter(QuizMenuActivity, int, String[]) is undefined
Appreciate any help. Code is posted below.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu);
ListView menuList=(ListView) findViewById(R.id.ListView_Menu);
String [] items = new String[] { getResources().getString(R.string.menu_item_Play),
getResources().getString(R.string.menu_item_scores),
getResources().getString(R.string.menu_i开发者_如何学Ctem_settings),
getResources().getString(R.string.menu_item_help)};
ArrayAdapter <string> adapt = new ArrayAdapter<string> (this,
R.layout.menu_item, items);
menuList.setAdapter(adapt)
This might work:
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String [] items = new String[] { getResources().getString(R.string.menu_item_Play),
getResources().getString(R.string.menu_item_scores),
getResources().getString(R.string.menu_item_settings),
getResources().getString(R.string.menu_item_help)};
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, items));
Why dont u use Map than make the Array> fill the map with the items add the map to the Array and than convert the array into String[]..
this.setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,R.array.DateEven));
精彩评论