老师,您好,为什么我的代码运行出来整个界面是空白呢?
package com.example.demo_listview;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
public class MainActivity extends Activity {
private ListView listView;
//private ArrayAdapter<String> arr_adapter;
private SimpleAdapter sim_adapter;
private List<Map<String, Object>> datalist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView=(ListView) findViewById(R.id.listView);
datalist=new ArrayList<Map<String,Object>>();//实例化数据源
sim_adapter=new SimpleAdapter(this, getData(),R.layout.sim_item, new String[]{"pic","text"}, new int[]{R.id.imageview,R.id.textview});
//String[] arr_data={"慕课1","慕课2","慕课3","慕课4"};
//arr_adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arr_data);
//listView.setAdapter(arr_adapter);
listView.setAdapter(sim_adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
private List<Map<String, Object>> getData(){
for(int i=20;i<20;i++)
{
Map<String, Object> map=new HashMap<String,Object>();
map.put("pic", R.drawable.ic_launcher);
map.put("text", "imooc"+i);
datalist.add(map);
}
return datalist;
}
}