怎么添加button来处理listview的多项选择结果

shaode01 2016-06-02 09:34:30
我在xml里面这样设置
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.helloworld.DisplayMessageActivity">
<Button
android:id="@+id/collect"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:onClick="saveCollect"
android:text="@string/button_collect" />
<ListView android:id="@+id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000ff"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>

java代码里什么都不加的话运行起来为什么看不到这个button呢?我是初学者,不知道这里面的工作原理是什么样的,为什么在activity_mail.xml里面添加button就能看到而在别的xml里面就不行呢?
我想用这个button来获取listview的多项选择结果
在java代码里面这样写可以吗?
   public void saveCollect(View v) {
long[] pos = getListView().getCheckedItemIds();


}
...全文
87 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
yezhichonger 2016-06-03
  • 打赏
  • 举报
回复
button显示不出是因为你加了这个:android:layout_weight="1" listview把所有空间都占了

80,348

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧