我试图创建一个AlertDialog,里面有一个NumberPicker。
但是,它只显示两个分隔符,而不显示文本。
请参阅http://imageshack.com/a/img673/8149/aWHQfj.png
我正在使用:
android:minSdkVersion="11"
android:targetSdkVersion="19"代码:
private void showInputDialog() {
Context context = getActivity();
RelativeLayout linearLayout = new RelativeLayout(context);
final NumberPicker numberPicker = new NumberPicker(context);
numberPicker.setMaxValue(1);
numberPicker.setMinValue(100);
numberPicker.setWrapSelectorWheel(false);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
linearLayout.setLayoutParams(params);
linearLayout.addView(numberPicker,numPicerParams);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
alertDialogBuilder.setTitle("Number of strokes");
alertDialogBuilder.setView(linearLayout);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
int score = numberPicker.getValue();
if (mRows != null) {
if (mClickedColIndex > 10) mClickedColIndex -= 1;
mClickedPlayer.setManualScore(mClickedColIndex, score);
} else {
if (mClickedRowIndex > 10) mClickedRowIndex -= 1;
mClickedPlayer.setManualScore(mClickedRowIndex, score);
}
mClickedText.setText(Integer.toString(score));
setupScorecard();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}我已经对这个主题做了很多搜索,但我还没有找到任何可行的解决方案。
还有,我不能设置的是:android:numberPickerStyle in styles.xml。
有人对此有什么想法吗?
发布于 2014-12-23 11:43:31
改变这一点:
numberPicker.setMaxValue(1);
numberPicker.setMinValue(100);在这方面:
numberPicker.setMaxValue(100);
numberPicker.setMinValue(1);最小值不能高于最大值。
https://stackoverflow.com/questions/27619576
复制相似问题