【发布时间】:2014-12-23 11:35:49
【问题描述】:
我正在尝试创建一个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。
有人对此有任何想法吗?
【问题讨论】:
-
我刚刚注意到我颠倒了最小值和最大值。改变它解决了我的问题。
标签: android styles numberpicker