【问题标题】:Android AutoCompleteTextView CursorAdapter Fails if using custom layout如果使用自定义布局,Android AutoCompleteTextView CursorAdapter 失败
【发布时间】:2011-04-06 12:40:07
【问题描述】:

我有一个 AutoCompleteTextView 和一个 CursorAdapter。现在一切正常,您可以将它与android.R.layout.simple_dropdown_item_1line 一起使用,但是当您尝试为自定义布局充气时,Android 放弃了。

作品

@Override
public void bindView(View view, Context context, Cursor cursor) {
  final String text = convertToString(cursor);
  ((TextView) view).setText(text);
}


@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
  final LayoutInflater inflater = LayoutInflater.from(context);
  final View view =
          inflater.inflate(
                    android.R.layout.simple_dropdown_item_1line,
                  parent, false);

 return view;
}

不起作用

@Override
  public void bindView(View view, Context context, Cursor cursor) {
      final String text = convertToString(cursor);

      ((TextView) findViewById(R.id.txtAutoCompleteText)).setText(text);
  }


  @Override
  public View newView(Context context, Cursor cursor, ViewGroup parent) {
      final LayoutInflater inflater = LayoutInflater.from(context);
      final View view =
              inflater.inflate(
                        //android.R.layout.simple_dropdown_item_1line,
                      R.layout.auto_complete_item,
                      parent, false);

     return view;
  }

我知道有人已经问过类似的问题并被标记为已回答,但它不满足我的查询。

我有什么遗漏或者这是不可能的。

【问题讨论】:

    标签: android android-layout autocompletetextview android-cursoradapter


    【解决方案1】:

    向我们展示您的 auto_complete_item.xml 和您的光标适配器并调用 db 以获取光标。

    您似乎没有为 auto_complete_item.xml 中的文本选择正确的默认资源 ID,即“@android:id/list”,因此系统不知道如何获取要填写的文本字段你的 auto_complete_item

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-13
      相关资源
      最近更新 更多