单击按钮时,是否可以制作一个内部带有评级栏的“类似 AlertDialog 的显示”?如果是,我能否获得输入的评分值?谢谢。
问问题
1248 次
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 回答