0

次のコードは、2.3.3ではなくICSで適切に機能します。

チェックボックス付きのカスタムトーストを使用すると、ICSでclickEventsが発生します。

カスタムダイアログを作成してアクティビティとして呼び出す必要がありますか、それとも解決できますか?

public void showToastwithImage(String text, int imageID, boolean forceShow) {

    if (prefs.getBoolean("prefs_showHelp", true)) {
        // create the view
        View view = inflateView(R.layout.message_panel);

        // set the image in the view
        ImageView im = (ImageView) view.findViewById(R.id.panel_icon);
        im.setImageResource(imageID);

        // set the text in the view
        TextView tv = (TextView) view.findViewById(R.id.message);
        tv.setText(text);

        CheckBox cb = (CheckBox) view.findViewById(R.id.checkBox1);

        if(forceShow){
            cb.setVisibility(View.GONE);
        }else{
            cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    SharedPreferences.Editor editor = prefs.edit();
                    editor.putBoolean("prefs_showHelp", false);
                    editor.commit();
                }
            });
        }


        // show the toast
        Toast toast = new Toast(this);
        toast.setView(view);
        toast.setDuration(Toast.LENGTH_LONG);
        toast.show();
    }

}
private View inflateView(int resource) {
    LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    return vi.inflate(resource, null);
}
4

2 に答える 2

1

custom dialog is better than toast...

カスタムダイアログでビューを簡単に設定できます。トーストは、対話せずにフラッシュメッセージ用です。

Dialog dialog = new Dialog(YourActivityName.this);
dialog.setContentView(R.layout.dialoglayout);

ImageView im = (ImageView) dialog.findViewById(R.id.panel_icon);
TextView tv = (TextView) dialog.findViewById(R.id.message);
CheckBox cb = (CheckBox) dialog.findViewById(R.id.checkBox1);

dialog.show();
于 2012-05-16T08:46:53.733 に答える
1

トーストは、2秒または3.5秒間表示されるため、ユーザーとの対話を提供せずに短いメッセージを表示するために使用することになっています。したがって、ユーザーがチェックボックスを操作するには、ダイアログまたはアクティビティ(ダイアログテーマ付き)を使用することをお勧めします。

于 2012-05-16T08:47:21.570 に答える