我正在使用'ListView'和'ArrayAdapter'。我創建了一個名爲listview_simple_layout.xml的新XML文件。Android Studio ArrayAdapter不起作用程序崩潰
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:background="#ff0"
android:textColor="#f00"
android:textSize="30dp"
android:textStyle="bold|italic"
android:typeface="serif" />
</LinearLayout>
內onCreate方法,當我通過這個XML文件ArrayAdapter的構造和運行程序,它崩潰。請幫我... 這裏是我的onCreate功能:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Employee[] eList = new Employee[5];
eList[0] = new Employee("Jagga", "Detroit Michigan", 1, 5000.0);
eList[1] = new Employee("Bagga", "Alexandria Virginia", 2, 15000.0);
eList[2] = new Employee("Haji", "San Diego California", 3, 25000.0);
eList[3] = new Employee("Saqa", "Lahore Pakistan", 4, 35000.0);
eList[4] = new Employee("Saqa", "Lahore Pakistan", 4, 35000.0);
ListView lv = (ListView) findViewById(R.id.listView);
ArrayAdapter<Employee> ad = new ArrayAdapter<Employee>(this, R.layout.listview_simple_layout, eList);
lv.setAdapter(ad);
}
但每當我發表意見lv.setAdapter(廣告),它工作正常,但沒有顯示輸出。