【问题标题】:How to select multiple contacts and pass them to another Intent in android如何选择多个联系人并将它们传递给android中的另一个Intent
【发布时间】:2012-05-13 23:52:51
【问题描述】:

我有一个项目列表,在活动中的每个项目之前都有一个复选框。 use 可以选择多个项目,然后将这些项目传递给另一个意图。 谁能告诉我如何根据复选框选择来识别选择的项目。

我为列表中的每个项目使用以下布局

<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:padding="6dip" android:layout_height="?android:attr/listPreferredItemHeight">
<CheckBox
    android:id="@+id/result_icon"        
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentBottom="true"
    android:layout_marginRight="6dip"        
    android:src="@drawable/ic_launcher"/>
<TextView
    android:id="@+id/result_name"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"        
    android:layout_toRightOf="@id/result_icon"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"        
    android:layout_alignWithParentIfMissing="true"                
    android:gravity="center_vertical"
    android:text="Title" />
<TextView  
    android:id="@+id/result_second_line"
    android:layout_width="fill_parent"
    android:layout_height="26dip"      
    android:layout_toRightOf="@id/result_icon"
    android:layout_below="@id/result_name"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"        
    android:singleLine="true"
    android:ellipsize="marquee"
    android:text="Second line" />

【问题讨论】:

  • 浏览这个link
  • 这对 Satheesh 有效!非常感谢!

标签: android listview multipleselection


【解决方案1】:

在这种情况下,我假设您为 Check Box 维护了一个 ArrayList,这意味着选中了哪个复选框或未选中哪个复选框。通过这种方式,您将获得要发送到另一个活动的联系人。

现在要将联系人值从一个活动传递到另一个活动,您可以使用Bundle

Bundle mBundle=new Bundle();
        mBundle.putStringArrayList("KeyValue", ArrayList Contact name);
        mIntent.putExtras(mBundle);

你可以像下面的代码一样在下一个活动中获取 Bundle。

Bundle mBundle=getIntent().getBundleExtra("KeyValue");

【讨论】:

  • 如果您可以根据需要引用可通过Bundle 传递的数据类型。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-21
  • 1970-01-01
  • 2012-02-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多