arrayadpter有错误
源代码如下:
package com.example.androidarrayadapter;
import android.support.v7.app.ActionBarActivity;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
@SuppressLint("NewApi")
public class MainActivity extends Activity {
private ListView listView;
private ArrayAdapter<String> arr_adapter;
private SimpleAdapter sim_adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView=(ListView) findViewById(R.id.listView);
//1.新建一个数据适配器
//ArrayAdapter(上下文,当前listview加载的每一个列表项代表的布局文件,数据源 )
//2.适配器加载数据源
String[]arr_data={"慕课网1","慕课网2","慕课网3","慕课网4"};
arr_adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,arr_data);
//3.视图加载适配器
listView.setAdapter(arr_adapter);
}
}