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方法建立连接
ListView list;
Button btn;
list = (ListView)findViewById(R.id.lv);
btn = (Button)findViewById(R.id.btn);
接下来就是想想怎么构造Adapter,首先还是得新建个adapter,当然还有存储数据用的ArrayList(或者其他的)