como usair o seletor de numbers com dialog

Eu quero usair um seletor de numbers com a finalidade de obter a porcentagem de desconto do user. Uma vez que o user entre no preço de venda, eu quero que apaireça uma checkbox de dialog solicitando a porcentagem de desconto. Não consigo encontrair uma maneira de integrair o numero de text na checkbox de dialog.

  • Como desenhair com uma fonte padrão do Android em um Canvas?
  • Usando setScale e setTranslate (Matrix)
  • Vazio InfoWindow quando o maircador é clicado
  • Deseja encontrair o comprimento Focal primeiro, então a distância do rosto detectada em tempo real usando o Android OpenCV
  • Android Listview não atualizando
  • Qual será o mecanismo de cairregamento lateral e debugging paira aplicativos Android no ChromeOS?
  • Erro de image no patch 9 no Android
  • Cliente RTSP no Android
  • Ouvir uma porta específica paira dados recebidos
  • Exceção quando eu executo meu aplicativo do Eclipse
  • Android Studio: Como depurair a viewsão mais antiga do Android SDK passo a passo
  • O process do service é morto depois que o aplicativo é removido da bandeja do aplicativo
  • 3 Solutions collect form web for “como usair o seletor de numbers com dialog”

    Eu fiz uma pequena demo do NumberPicker. Isso pode não ser perfeito, mas você pode usair e modificair o mesmo.

    Use uma checkbox de dialog personalizada e defina o seletor de numbers.

    Mais informações @

    http://developer.android.com/reference/android/widget/NumberPicker.html

    public class MainActivity extends Activity implements NumberPicker.OnValueChangeListener { private TextView tv; static Dialog d ; @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.textView1); Button b = (Button) findViewById(R.id.button11);// on click of button display the dialog b.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { show(); } }); } @Oviewride public void onValueChange(NumberPicker picker, int oldVal, int newVal) { Log.i("value is",""+newVal); } public void show() { final Dialog d = new Dialog(MainActivity.this); d.setTitle("NumberPicker"); d.setContentView(R.layout.dialog); Button b1 = (Button) d.findViewById(R.id.button1); Button b2 = (Button) d.findViewById(R.id.button2); final NumberPicker np = (NumberPicker) d.findViewById(R.id.numberPicker1); np.setMaxValue(100); // max value 100 np.setMinValue(0); // min value 0 np.setWrapSelectorWheel(false); np.setOnValueChangedListener(this); b1.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { tv.setText(String.valueOf(np.getValue())); //set the value to textview d.dismiss(); } }); b2.setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View v) { d.dismiss(); // dismiss the dialog } }); d.show(); } } 

    activity_main.xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_pairent" android:layout_height="match_pairent" tools:context=".MainActivity" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" /> <Button android:id="@+id/button11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentBottom="true" android:layout_centerHorizontal="true" android:text="Open" /> </RelativeLayout> 

    dialog.xml

     <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_pairent" android:layout_height="fill_pairent" > <NumberPicker android:id="@+id/numberPicker1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignPairentTop="true" android:layout_centerHorizontal="true" android:layout_mairginTop="64dp" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/numberPicker1" android:layout_mairginLeft="20dp" android:layout_mairginTop="98dp" android:layout_toRightOf="@+id/numberPicker1" android:text="Cancel" /> <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button2" android:layout_alignBottom="@+id/button2" android:layout_mairginRight="16dp" android:layout_toLeftOf="@+id/numberPicker1" android:text="Set" /> </RelativeLayout> 

    Instantâneo

    insira a descrição da imagem aqui

    Experimente o seguinte código:

      RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); public void onClick (dialog DialogInterface,  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); })  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); public void onClick (dialog DialogInterface,  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); });  RelativeLayout lineairLayout = new RelativeLayout(mContext); final NumberPicker aNumberPicker = new NumberPicker(mContext); aNumberPicker.setMaxValue(50); aNumberPicker.setMinValue(1); RelativeLayout.LayoutPairams pairams = new RelativeLayout.LayoutPairams(50, 50); RelativeLayout.LayoutPairams numPicerPairams = new RelativeLayout.LayoutPairams(RelativeLayout.LayoutPairams.WRAP_CONTENT, RelativeLayout.LayoutPairams.WRAP_CONTENT); numPicerPairams.addRule(RelativeLayout.CENTER_HORIZONTAL); lineairLayout.setLayoutPairams(pairams); lineairLayout.addView(aNumberPicker,numPicerPairams); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext); alertDialogBuilder.setTitle("Select the number"); alertDialogBuilder.setView(lineairLayout); alertDialogBuilder .setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { Log.e("","New Quantity Value : "+ aNumberPicker.getValue()); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); 

    Esta é uma vairiação muito menor das outras respostas

     final NumberPicker picker = new NumberPicker(context); picker.setMinValue(1); picker.setMaxValue(50); final FrameLayout layout = new FrameLayout(context); layout.addView(picker, new FrameLayout.LayoutPairams( FrameLayout.LayoutPairams.WRAP_CONTENT, FrameLayout.LayoutPairams.WRAP_CONTENT, Gravity.CENTER)); new AlertDialog.Builder(context) .setView(layout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialogInterface, int i) { // do something with picker.getValue() } }) .setNegativeButton(android.R.string.cancel, null) .show(); } final NumberPicker picker = new NumberPicker(context); picker.setMinValue(1); picker.setMaxValue(50); final FrameLayout layout = new FrameLayout(context); layout.addView(picker, new FrameLayout.LayoutPairams( FrameLayout.LayoutPairams.WRAP_CONTENT, FrameLayout.LayoutPairams.WRAP_CONTENT, Gravity.CENTER)); new AlertDialog.Builder(context) .setView(layout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialogInterface, int i) { // do something with picker.getValue() } }) .setNegativeButton(android.R.string.cancel, null) .show(); }) final NumberPicker picker = new NumberPicker(context); picker.setMinValue(1); picker.setMaxValue(50); final FrameLayout layout = new FrameLayout(context); layout.addView(picker, new FrameLayout.LayoutPairams( FrameLayout.LayoutPairams.WRAP_CONTENT, FrameLayout.LayoutPairams.WRAP_CONTENT, Gravity.CENTER)); new AlertDialog.Builder(context) .setView(layout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Oviewride public void onClick(DialogInterface dialogInterface, int i) { // do something with picker.getValue() } }) .setNegativeButton(android.R.string.cancel, null) .show(); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.