【问题标题】:Android listview with SimpleCursorAdapter带有 SimpleCursorAdapter 的 Android 列表视图
【发布时间】:2014-10-28 22:05:02
【问题描述】:

我正在创建一个应用程序,它基本上将从 SQLite 数据库中提取数据并使用 SimpleCursorAdapter 显示 ListView

我的问题是在使用 setOnItemClickListener 根本不起作用。

这是我的活动中的onCreate 事件

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_categoria);
    //Mostrando lista
    dbcon = new SQLController(this);
    dbcon.open();
    lv = (ListView) findViewById(R.id.listView1);

    Cursor cursor = dbcon.readData();
    String[] from = new String[] { DBhelper.MEMBER_ID, DBhelper.MEMBER_NAME };
    int[] to = new int[] { R.id.tv_descripcion, R.id.tv_Titulo };

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(Categoria.this,
            R.layout.fila, cursor, from, to);               
    adapter.notifyDataSetChanged();
    lv.setAdapter(adapter);


    //Fin de mostrar lista
    Log.d("jose", "Salio del Adapter");
    //Click en el elemento de la lista
    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            Log.d("jose", "Toco la lista"); 
            Toast.makeText(getApplicationContext(), "tocado", Toast.LENGTH_SHORT).show()
        }
    });     



}

【问题讨论】:

    标签: android listview simplecursoradapter android-cursoradapter


    【解决方案1】:

    其实很简单。要工作,您只需在可描述行的 xml 中添加一行。在 botonoes 中添加了 xml 属性

    android:focusable = "false"

    问题解决了。自从 setOnItemClick funsona listview

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-26
      • 2016-10-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多