List_classtable.xml
<?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"
android:orientation="vertical" >
<TextView
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text1"
android:textColor="@android:color/secondary_text_dark_nodisable"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text2"
android:textColor="@android:color/secondary_text_dark_nodisable"/>
</LinearLayout>
Activit_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:id="@+id/activity_timetable_list"
android:layout_width="300dip"
android:layout_height="match_parent"
android:clipToPadding="false"
android:divider="#19999999"
android:dividerHeight="20dip"
android:fadingEdge="none"
android:paddingTop="42dip" />
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
List<Map<String, Object>> data;
ListView list;
SimpleAdapter spad;
ArrayList arraylist;
private List<Map<String, Object>> data() {
// TODO Auto-generated method stub
data = new ArrayList<Map<String, Object>>();
/*
for(int i=0;i<2;i++){
Map<String, Object> map=new HashMap<String, Object>();
map.put("image_", ima[i]);
map.put("text_1", list_text1[i]);
map.put("text_2", list_text2[i]);
data.add(map);
}*/
Map<String, Object> map = null;
for (int n = 0; n < arraylist.size(); n++) {
map = new HashMap<String, Object>();
map.put("text_1", "课程名: " + arraylist.get(n));
data.add(map);
}
return data;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
arraylist=new ArrayList();
//加入课程名
arraylist.add("mathematical");
arraylist.add("chemist");
list=(ListView) findViewById(R.id.activity_timetable_list);
list=(ListView) findViewById(R.id.activity_timetable_list);
spad=new SimpleAdapter(MainActivity.this, data(), R.layout.list_classtable,
new String[]{"text_1","text_2"}, new int[]{R.id.text1,R.id.text2});
list.setAdapter(spad);
}
}