【问题标题】:Android remove values from SpinnerAndroid 从 Spinner 中删除值
【发布时间】:2011-11-05 00:16:56
【问题描述】:

我有一个使用 SimpleCursorAdapter 从光标填充的微调器 我想根据变量从这个适配器中删除一些值 我尝试了类似的方法,但效果不佳

SimpleCursorAdapter toListAdapter = new SimpleCursorAdapter(MoreTicketSalesActivity.this, R.layout.generic_spinneritem, cursor, column,
        viewIds) {


@Override
public void bindView(View view, Context context, Cursor cursor) {
    super.bindView(view, context, cursor);
        if (cursor.getLong(3) < session.getStopIndex()) {
            view.setVisibility(View.INVISIBLE);
        }
    }
};

请帮帮我

【问题讨论】:

    标签: android spinner


    【解决方案1】:

    所以我找到了一个最适合我的解决方案

    TextView textView = (TextView) view.findViewById(R.id.spinner_item_name);
    int index = cursor.getInt(cursor.getColumnIndex("index"));
    String name = cursor.getString(cursor.getColumnIndex("name"));
    textView.setText(name);
    if (index <= this.index) {
        textView.setTextColor(Color.LTGRAY);
        textView.setClickable(true);
    } else {
        textView.setTextColor(Color.BLACK);
        textView.setClickable(false);
    }
    

    【讨论】:

      【解决方案2】:

      首先,您检查变量的值并获取要从光标中删除的项目的位置。

      1. 然后从光标中删除这些值(通过 remove(position of value) 等)。

      2. 然后使用toListAdapter.notifyDataSetChanged();

      【讨论】:

      • 如何从光标中删除值...光标是只读的(据我所知)。光标带有值并且是正确的。也许我必须解释更多。我有 2 个使用相同光标填充的微调器。是站台名称。如果我在 From spinner 中选择某些内容,那么在 To spinner 中,我必须删除从选定站点传递的所有值。
      • 你为什么不创建字符串数组或列表并使用它。
      • 因为在光标中我有 id、index、name。我需要所有这些价值观。我可以制作一个列表 List 但我在渲染微调器时遇到了困难。
      • 试试这个:创建一个新数据库并在表中放入所有数据。然后检查变量值更新表并生成新游标并使用它。
      • 如果您阅读我上面的评论,我说我有 2 个微调器。根据第一个旋转器的选择,第二个旋转器被过滤。如果我像你一样建议在数据库中添加每次值,我认为这会很耗时。
      猜你喜欢
      • 1970-01-01
      • 2015-05-19
      • 2015-05-23
      • 2015-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多