【问题标题】:Display android listview based upon listview selection根据列表视图选择显示android列表视图
【发布时间】:2010-08-04 10:21:15
【问题描述】:

我有一个 listview 说在这种情况下有值:

英国, 美国, 法国

这些值是从我的 string.xml 文件中保存的静态数组中提取的。此外,在 string.xml 中有 3 个数组,每个数组都指的是英国、美国和法国,基本上我想根据用户的 onclick 事件将这些数组加载到一个新的列表视图中。

基本上我不知道如何将用户选择传递给新的列表视图并相应地填充。我知道这个过程包含了意图的使用,但作为一个 android 新手,我不完全确定如何!

非常感谢任何帮助!

干杯

【问题讨论】:

    标签: android listview android-intent


    【解决方案1】:

    第一个上下文(可以是活动/服务等)

    你有几个选择:

    1) 使用来自Intent 的Bundle:

    Intent mIntent = new Intent(this, Example.class);
    Bundle extras = mIntent.getExtras();
    extras.putString(key, value);  
    

    2) 创建一个新的捆绑包

    Intent mIntent = new Intent(this, Example.class);
    Bundle mBundle = new Bundle();
    mBundle.extras.putString(key, value);
    mIntent.putExtras(mBundle);
    

    3)使用Intent的putExtra()快捷方式

    Intent mIntent = new Intent(this, Example.class);
    mIntent.putExtra(key, value);
    

    新上下文(可以是活动/服务等)

    Intent myIntent = getIntent(); // this getter is just for example purpose, can differ
    if (myIntent !=null && myIntent.getExtras()!=null)
         String value = myIntent.getExtras().getString(key);
    }
    

    注意: Bundle 对所有原始类型、Parcelable 和 Serializable 都有“get”和“put”方法。我只是将字符串用于演示目的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-27
      • 2015-12-22
      • 1970-01-01
      • 1970-01-01
      • 2015-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多