How to put a search bar in a warning dialog?

I want the warning dialog to appear after clicking the button in order to have a search bar so that a person can change the value from 1-48. I created my own xml that has a search bar and two text views, and I would like the dialog box to have two buttons, one just cancels the dialog and the other works more. Here is the code I have.

<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <SeekBar android:max="48" android:layout_height="wrap_content" android:id="@+id/seekBar1" android:layout_width="fill_parent" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_marginTop="74dp"></SeekBar> <TextView android:text="Change Hour Range" android:layout_height="wrap_content" android:id="@+id/textView1" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_width="wrap_content" android:layout_alignParentTop="true" android:layout_centerHorizontal="true"></TextView> <TextView android:text="Only most recent positions" android:layout_height="wrap_content" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_below="@+id/textView1" android:layout_centerHorizontal="true" android:layout_marginTop="15dp"></TextView> </RelativeLayout> 

Here is the alert dialog that I still have

 new AlertDialog.Builder(ImTracking.this) //is there something like setcontentview for alert dialogs? .setPositiveButton("Cancel", null) .setNegativeButton("OK", new DialogInterface.OnClickListener() { // does some work here 
+7
source share
2 answers

Yep builder.setView(View v); here is how you can use it.

  LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View layout = inflater.inflate(R.layout.yourLayoutId, (ViewGroup) findViewById(R.id.yourLayoutRoot)); AlertDialog.Builder builder = new AlertDialog.Builder(this) .setView(layout); AlertDialog alertDialog = builder.create(); alertDialog.show(); SeekBar sb = (SeekBar)layout.findViewById(R.id.yourSeekBar); sb.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){ //Do something here with new value } }); 

Edit: added progressListener for sample code. Note that you cannot get a link to your SeekBar until after , you call alertDialog.show (), if the SeekBar is not displayed, findViewById () returns null. Also note that you should use layout.findViewById(); , because the SeekBar is a child of the RelativeLayout to which the "layout" refers.

+13
source
  //This is the code you seek! public void ShowDialog(){ final AlertDialog.Builder popDialog = new AlertDialog.Builder(this); final SeekBar seek = new SeekBar(this); seek.setMax(255); seek.setKeyProgressIncrement(1); popDialog.setIcon(android.R.drawable.btn_star_big_on); popDialog.setTitle("Please Select Into Your Desired Brightness "); popDialog.setView(seek); seek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser){ txtView.setText("Value of : " + progress); } 

Or you can look in this tutorial

+2
source

All Articles