-1
我不知道如何将对话框功能添加到我的onclick功能,我希望它对话框被召唤一旦我点击按钮。如何在onclick函数中调用我的对话框功能?
这是onCreate方法
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview);
fillData();
boxAdapter = new ListAdapter(this, products);
ListView lvMain = (ListView) findViewById(R.id.lvMain);
lvMain.setAdapter(boxAdapter);
Button btn = (Button) findViewById(R.id.insert);
OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
}
};
/** Setting the event listener for the add button */
btn.setOnClickListener(listener);
}
那么这是我的对话功能,这是在同一个Java类
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
// Get the layout inflater
LayoutInflater inflater = this.getLayoutInflater();
// Inflate and set the layout for the dialog
// Pass null as the parent view because its going in the dialog layout
builder.setView(inflater.inflate(R.layout.dialog, null))
// Add action buttons
.setPositiveButton(R.string.Insert, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// DialogFragment.this.getDialog().cancel();
}
});
return builder.create();
}
获取答案在这里http://stackoverflow.com/问题/ 18842277 /对话框泛型函数,返回布尔基于对用户的按钮按下/ 18842412#18842412 –