为什么会白屏
Java;
package com.example.eat1;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
private ListView listview;
private ArrayAdapter<String>arr_adapter;
private SimpleAdapter simp_adapter;
private List<Map<String,Object>>dataList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listview=(ListView) findViewById(R.id.listView);
String[] arr_data={"慕课网1","慕课网2","慕课网1","慕课网2","慕课网1","慕课网2","慕课网1","慕课网2","慕课网1","慕课网2"};
dataList=new ArrayList<Map<String,Object>>();
arr_adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arr_data);
simp_adapter=new SimpleAdapter(this,getData(),R.layout.item,new String[]{"pic","text"},new int[] {R.id.pic,R.id.text});
// 视图加载适配器
listview.setAdapter(simp_adapter);
}
private List<Map<String,Object>> getData(){
for(int i=0;i<20;i++){
Map<String,Object>map=new HashMap<String, Object>();
map.put("pic", R.drawable.ic_launcher);
map.put("text", "慕课网"+i+1);
}
return dataList;
}
}
xml;
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="@+id/pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_launcher"
/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="#000000"
android:text="demo"
></TextView>
</LinearLayout>