I'm having trouble with number picker. When i try to add min and max values in java code for the numberpicker i get this error
Attempt to invoke virtual method 'void android.widget.NumberPicker.setMinValue(int)' on a null object reference
Obviously, it doesn't recognize my numberpicker, so that i can not add the values.
Somebody found a solution to this problem here, but it doesn't really fit me. Because in the next dialog i'll need another numberpicker and adjust it according to the previous one.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState){
AlertDialog.Builder bodyBuilder = new AlertDialog.Builder(getActivity());
LayoutInflater inflator = getActivity().getLayoutInflater();
bodyBuilder.setTitle(R.string.title);
NumberPicker np = (NumberPicker) getActivity().findViewById(R.id.nambir);
np.setMinValue(1);
np.setMaxValue(100);
final int npValue= np.getValue();
bodyBuilder.setView(inflator.inflate(R.layout.layout_diyalog, null))
.setPositiveButton("Continue", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int id){
Intent intent = new Intent(getActivity(), Olurmuki.class);
intent.putExtra("value", npValue);
startActivity(intent);
}
})
.setNegativeButton("Cancel",new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int id){
MyDialog.this.getDialog().cancel();
}
});
return bodyBuilder.create();
}