2013-06-21 6 views
1

У меня есть два сборщика чисел в макете, и я использую макет для окна AlertDialog. Однако у двух наборов цифр нет скроллеров, которые используются для увеличения/уменьшения значения. Также я не могу вручную вводить значения. Может ли кто-нибудь помочь мне найти ошибки.Android: NumberPicker не ведет себя должным образом

Dialog.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> 

код Snipper от деятельности, доступ к этому раскладку:

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(); 

ответ

3

Если вы не обеспечивают мин и Максу значения NumberPicker, приращение/декремент кнопки не будут отображаться.

Вы можете использовать setMaxValue и setMinValue вроде этого:

np1.setMaxValue(MAX); 
np1.setMinValue(MIN);