为什么OnItemClickListener不起作用且没有错误?

时间:2013-10-10 21:16:36

标签: android

我创建了一个用数据库中的数据充气的ListView。但我无法使onItemClick运行。抱歉我的英文不好,我希望找到帮助,当然所有的代码都是错的。我省略了onResume方法

public class MainActivity extends Activity implements android.widget.AdapterView.OnItemClickListener
    {
        private Cursor c;

        @Override
        public void onCreate(Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            recuperaNotas();
            Button add=(Button)findViewById(R.id.botonAdd);
            add.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0)
                {
                    Intent intent = new Intent(MainActivity.this, AddNota.class);
                    Bundle bundle = new Bundle();
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
            Button editar=(Button)findViewById(R.id.botonEditar);
            editar.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0)
                {
                    Intent intent = new Intent(MainActivity.this, ListaEdicion.class);
                    Bundle bundle = new Bundle();
                    intent.putExtras(bundle);
                    startActivity(intent);
                }
            });
        }

        public void recuperaNotas(){
            Nexum nexum = new Nexum(MainActivity.this);
            SQLiteDatabase db = nexum.getWritableDatabase();
            try{

                //MUESTRA DATOS DE LA DB
                ListView listView = (ListView) findViewById(R.id.listView);
                Cursor cursor= nexum.getCursor();
                startManagingCursor(cursor);

                String[] from = new String[]{nexum.C_FECHA,nexum.C_TITULO,nexum.C_ID};
                int[] to = new int[]{R.id.text1,R.id.text2,R.id.text3};

                ListAdapter cursorAdapter = new SimpleCursorAdapter(this, R.layout.row, cursor,from,to);
                listView.setAdapter(cursorAdapter);
                Toast.makeText(this, "ANTES", 4555).show();

                listView.setOnItemClickListener(MainActivity.this);
                        //.setOnItemClickListener(this);

            }catch(Exception e){
                Log.d("Error", "El mensaje de error es: " + e.getMessage());
            }finally {
                db.close();
                nexum.close();
            }
        }

        public void onItemClick(AdapterView<?> parent,View view,int position,
                                long rowId) {
            Log.v("TAG", "Hello");

        }

    }

0 个答案:

没有答案