-1
내 onclick 함수에 대화 상자 함수를 추가하는 방법을 모르겠다. 버튼을 클릭하면 대화 상자를 불러오고 싶습니다.onclick 함수에서 대화 상자 함수를 호출하는 방법은 무엇입니까?
이
/** 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);
}
다음이 여기 같은 자바 클래스
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/ : 당신이 인수
Bundle savedInstanceState
을 통과하지 않아도 당신의 대화 기능에서 403,210은 다음 버튼에 대한onClick
기능이 같은 함수를 호출 질문/18842277/dialogs-generic-function-return-boolean-based-on-user-button-press/18842412 # 18842412 –