ListView和何种列表,困惑了我很久
终于下决心把它们一次性搞搞清楚
从动态添加项开始写起吧。
首先我得有个ListView,好,先在xml布局文件里加一个,由于我要写的是动态添加,那么,再来个Button好了
<ListView
android:id="@+id/lv"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8">
</ListView>
<Button
android:id="@+id/btn"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:text="click the button!"/>
(把它俩放再LinearLayout里边,设置一下layout_weight感觉比较合理些)
其次,在代码中新建ListView和Button,并使用findViewById方法建立连接