android.widget.ListView是不是可以通过这个SimpleCursorAdapter界限视图 [英] android.widget.ListView is not a view that can be bounds by this SimpleCursorAdapter

查看:205
本文介绍了android.widget.ListView是不是可以通过这个SimpleCursorAdapter界限视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试着去得到BBDD一些数据用这种方法

Im trying to get some data from bbdd with this method

/**********************************************************************
 * * Obten todos los nombres
 * 
 */

public Cursor getNombres(){


       Cursor respuesta = db.rawQuery("select "+TABLE_ROW_ID+","+CNOMBRE+" from "+TABLE_NAME, null);

       return respuesta;
}

在这个类

  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);   
     //Creamos la instancia de DataBaseHelper, un cursor y aplicamos el metodo getNombres al cursor.
     ayudabbdd = new DataBaseHelper(this);
     Cursor nombresC;     
     nombresC = (Cursor) ayudabbdd.getNombres();  
     startManagingCursor(nombresC);

     //Mientras el cursor no este vacio rellenamos la lista con el adaptador, que nos sirve para conectar unos datos con el listview.
     if(nombresC!=null){
     ListAdapter adapter = new SimpleCursorAdapter(this, R.layout.listatab, nombresC, new String[] { "nombre" }, new int[] { R.id.lista });
     this.setListAdapter(adapter);
     this.getListView().setTextFilterEnabled(true);  
     }



     }

但登录猫返回我,

But log cat return me that

android.widget.ListView is not a  view that can be bounds by this SimpleCursorAdapter 

但是,在一些教程这是从一个BBDD阵列的方式,它们不具有问题

But in some tutorials this is the way to get an array from a bbdd and they don't have problem

推荐答案

如果你读<一个商务部href=\"http://developer.android.com/reference/android/widget/SimpleCursorAdapter.html#SimpleCursorAdapter%28android.content.Context,%20int,%20android.database.Cursor,%20java.lang.String%5B%5D,%20int%5B%5D%29\"相对=nofollow> SimpleCursorAdapter ,构造,它的方式是去precated,得到作为第五个参数TextViews的ID,从文档:

If you read the doc for SimpleCursorAdapter, the constructor, which by the way is deprecated, gets as 5th parameter the ids of TextViews, from the doc:

to->    The views that should display column in the "from" parameter. 
These should all be TextViews. The first N views in this list are 
given the values of the first N columns in the from parameter. 
Can be null if the cursor is not available yet.

相反,你给LISTA的ID,这是一个ListView。尝试使用此选项可以更改:

Instead you are giving the id of lista, which is a ListView. Try to change using this:

int[] to = new int[] { android.R.layout.simple_list_item_1 };
...
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.listatab, nombresC, new String[] { "nombre" }, to);

恩另外,如果你的活动扩展了ListActivity,在你的XML ListView控件必须具有此ID:

En plus, if your activity extends ListActivity, the ListView in your xml must have this id:

android:id="@android:id/android:list"

看看这个例如

这篇关于android.widget.ListView是不是可以通过这个SimpleCursorAdapter界限视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆