当扩展ListActivity然后不能使用onClickListener

时间:2012-03-16 05:31:46

标签: android

当我插入数据然后该数据显示在客户列表视图中并且还将按钮放在列表视图中所以,现在当单击按钮时执行某些操作,我需要为按钮创建onClickListener,所以当扩展ListActivity时不在我的Android应用程序中工作onClickListener ....     我也为此发送代码....

public class MydatabaseforlistActivity extends ListActivity {
    DbHelper dbhelper;
    SQLiteDatabase db;
    Button btnEdit,btnDel;
    String[] id;
    String[] title;
    int size;
    SimpleCursorAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    /*{
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        super.onCreate(savedInstanceState);*/
        //setContentView(R.layout.listcarda);
        dbhelper = new DbHelper(this);

        dbhelper.oninsert("HELLO");

        dbhelper.oninsert("hjkhkjhl");

        dbhelper.oninsert("happy mother");

        dbhelper.oninsert("happy sorry");

                  db=dbhelper.getReadableDatabase();
        Cursor c = db.query(DbHelper.TABLE_NAME, new String[] { DbHelper.U_ID,
                 DbHelper.TITLE }, null, null, null, null, null);
                 int i = 0;
        c.moveToFirst();
        size = c.getCount();
        id = new String[size];
        title = new String[size];
        while (c.moveToNext()) {
            id[i] = c.getString(1);
        //  title[i] = c.getString(2);
            i++;
            c.moveToNext();
        }
        c.close();
        db.close();
        //lv = getListView();
        setListAdapter(new Notes(this));

1 个答案:

答案 0 :(得分:1)

 public class MydatabaseforlistActivity extends ListActivity 
            implements onClickListener {

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);

                yourButton.setOnClickListener(this);

              }
           @Override
           public void onClick(View v) {
             // yourButton was clicked!
           }
       }   
  }