カスタムダイアログボックスを画面に表示するクラス(ペーパークリップ)を作成しました。私のアクティビティでは、Paperclip のインスタンスを作成し、アクティビティの上にダイアログ ボックスを表示します。私が欲しいのは、特定のボタンが押されると、アクティビティのコードが実行されることです。プロジェクト内のさまざまなアクティビティで再利用できるダイアログ ボックスが必要なため、このコードをアクティビティから実行したいと考えています。
クラスで変数を作成し、アクティビティでリスナーをアタッチすることを考えていました。これは良い方法ですか、それとももっと簡単な解決策はありますか?
public class Paperclip {
int i = 0;
Dialog myDialog;
TextView t;
int mid;
Context context2;
public Paperclip(Context context) {
super();
context2 = context;
}
public void Showit(final String[] Messages) {
final int lengte = Messages.length;
myDialog = new Dialog(context2, R.style.CustomDialogTheme);
myDialog.setContentView(R.layout.messagebox);
t = (TextView) myDialog.findViewById(R.id.message);
if (lengte != 0) {
if (i < lengte) {
t.setText(Messages[i]);
i++;
}
Button iets = (Button) myDialog.findViewById(R.id.mbja);
iets.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (i < lengte) {
t.setText(Messages[i]);
i++;
} else{
t.setText("Ik hoop dat deze informatie nuttig was. Klik op Ja om alles opnieuw te horen.");
i = 0;
}
}
});
}
Button iets2 = (Button) myDialog.findViewById(R.id.button2);
iets2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
myDialog.dismiss();
}
});
Button iets3 = (Button) myDialog.findViewById(R.id.button3);
iets2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//TODO: execute code from activity here.
}
});
myDialog.show();
}
}
ありがとう!