0

ボタンをクリックすると評価バーが表示される「AlertDialog のような表示」を作成することはできますか? はいの場合、入力された評価の値を取得できますか? ありがとう。

4

2 に答える 2

0

ダイアログのフラグメントを表示し、そこから選択を取得するためにアプリケーションで使用したコードを次に示します。

public class FeedChooserFragment extends DialogFragment {

    /**
     * Implement this interface if the activity needs to do something 
     * after the dialog has been dismissed.
     */
    public interface FeedChooserListener {
        public void onFeedSelected(NewsFeed feed, Object userData);
    }

    /**
     * Create a new instance of the fragment
     */
    public static FeedChooserFragment newInstance(Serializable userData) {
        FeedChooserFragment f = new FeedChooserFragment();

        Bundle args = new Bundle();
        args.putSerializable(Extra.USER_DATA, userData);
        f.setArguments(args);

        return f;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        // This is a list of items, but it could be a custom dialog showing some rating bar
        BaseActivity a = (BaseActivity) getActivity();
        List<NewsFeed> feed = a.getDataCache().getAllNewsFeed();
        adapter = new FeedAdapter(a);
        adapter.addAll(feed);

        // Here you would create a custom dialog, find the rating bar in the inflated view
        // and keep it ready for when the dialog gets dismissed. 
        AlertDialog.Builder builder = new AlertDialog.Builder(a);

        // Here you would set the button listeners instead of the listview listener
        builder.setAdapter(adapter, dialogClickListener);
        return builder.create();
    }

    private OnClickListener dialogClickListener = new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            NewsFeed selectedFeed = adapter.getItem(which);

            // This is where we try to notify the calling activity or fragment
            if (getActivity() instanceof FeedChooserListener) {
                ((FeedChooserListener) getActivity()).onFeedSelected(selectedFeed, userData);
            }

            if (getTargetFragment() instanceof FeedChooserListener) {
                ((FeedChooserListener) getTargetFragment()).onFeedSelected(selectedFeed, userData);
            }

            dialog.dismiss();
        }
    };

    private Object userData;
    private FeedAdapter adapter;
}
于 2012-07-29T08:53:59.733 に答える
0

はい、可能です、このようなことを試してみてください...

PopupWindow pw;    
//We need to get the instance of the LayoutInflater, use the context of this activity
LayoutInflater inflater = (LayoutInflater) TouchPaint.this
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//Inflate the view from a predefined XML layout
View layout = inflater.inflate(R.layout.popup,
        (ViewGroup) findViewById(R.id.popup_element));

//popup : name of the XML file which includes the popup_element(can be a linear layout which includes the rating bar)

pw = new PopupWindow(layout,70, 220, true);
pw.showAtLocation(layout, Gravity.LEFT,100,200);
rb  =(RatingBar)layout. findViewById(R.id.RatingBar);      
rb.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {
        // To Do code
                    pw.dismiss();
    }
});
于 2012-07-29T08:55:30.200 に答える