我在布局中有两个数字选择器,我正在使用 AlertDialog Box 的布局。但是,这两个数字选择器没有用于增加/减少值的滚动条。我也无法手动输入值。任何人都可以帮我找到错误。
对话框.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/llinner"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<NumberPicker
android:id="@+id/attnp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:id="@+id/llinnermost"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="50sp">
<TextView
android:id="@+id/innertv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="out of"
android:textSize="20sp"
android:paddingLeft="15sp"
android:paddingRight="15sp" />
</LinearLayout>
<NumberPicker
android:id="@+id/attnp2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
来自访问此布局的活动的代码片段:
LayoutInflater lf = LayoutInflater.from(List_of_Courses.this);
final View DialogView = lf.inflate(R.layout.dialog, null);
final NumberPicker np1 = (NumberPicker) DialogView.findViewById(R.id.attnp1);
final NumberPicker np2 = (NumberPicker) DialogView.findViewById(R.id.attnp2);
np1.setValue(prevatt);
np2.setValue(prevtot);
final AlertDialog.Builder alert = new AlertDialog.Builder(List_of_Courses.this);
alert.setTitle(cn+" - Attendance").setView(DialogView).setPositiveButton("OK",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichbutton) {
if(np1.getValue() == 0 || np2.getValue() == 0)return;
int att = np1.getValue();
int tot = np2.getValue();
if(att<=tot && tot>0){
db.UpdateAttendanceinSingleCourse(courseid, att, tot);
Toast.makeText(getApplicationContext(), "Attendance Updated", Toast.LENGTH_SHORT).show();
}
else {
RaiseException();
}
db.close();
onResume();
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichbutton) {
Log.v("CancelDialog", "User clicked Cancel");
}
});
alert.show();