Android ListView使用

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);

        }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值