开发者

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));
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜