【问题标题】:Selected Spinner Item as String for a new Cursor选定的微调器项目作为新光标的字符串
【发布时间】:2013-12-14 00:01:07
【问题描述】:

现在我几乎完成了我的应用程序的编写。我需要的只是一点帮助,通过一个简单的游标适配器从我的数据库填充的微调器中获取选定的字符串值。我不确定如何从微调器中获取字符串并将其传递给不同的游标并在查询中使用该字符串,该字符串将根据微调器的第一选择进行填充,以此类推其他微调器。

这是我用于我的一个微调器的代码。

vType = (Cursor) DataBaseHelper.getPowersportsType();
    this.startManagingCursor(vType);

        SimpleCursorAdapter scaType = new SimpleCursorAdapter(this, 
                android.R.layout.simple_spinner_item, 
                vType,
                new String [] {DataBaseHelper.POWERSPORTS_TYPE},
                new int[] {android.R.id.text1});

        scaType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        vTypeSpinner = (Spinner) findViewById(R.id.typeSpinner);
        vTypeSpinner.setAdapter(scaType);

这是我对 xml 布局中下一个微调器的查询

static String MakeWhere = "POWERSPORTS_TYPE=?";
public static Cursor getPowersportsMake(){
return myDataBase.query(POWERSPORTS_TABLE, 
    new String [] {POWERSPORTS_ID, POWERSPORTS_MAKE}, 
    MakeWhere, 
    null, 
    POWERSPORTS_MAKE, 
    null, 
    null);
}

欢迎任何cmets或建议。

【问题讨论】:

    标签: android string cursor spinner simplecursoradapter


    【解决方案1】:

    要选择项目,您需要设置onItemSelectedListener

    那么在你的 onItemtSelected 中你要做的就是

    String selection = vTypeSpinner.getSelectedItem().toString();
    

    【讨论】:

    • 那么我将如何使用在 Spinner 中选择的字符串作为我的查询中的变量?
    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多