当我插入数据时,数据会显示在客户 ListView 中,并将按钮放在 ListView 中 所以,现在当单击按钮时执行一些操作,因此我需要为按钮创建 onClickListener,因此当扩展 ListActivity 时则不会在我的 android 应用程序中处理 ClickListener .... 我也为此发送了代码....
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));
最佳答案
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!
}
}
}
关于android - 当扩展 ListActivity 然后不工作 onClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9732405/