当edittext值移动rangeseekbar时,如何将EditText值设置为RangeSeekbar?

时间:2013-12-14 10:15:27

标签: android android-layout android-edittext

我在Android中使用customRangeSeekBar时遇到一个问题当基于Edittext的rangeseekbar电影值我的RangeSeekbar值起始值起始值0和结束值30

我的要求是假设我将采用两个edittexts

firstedittext值为10,第二个edittextvalue为20,基于此值RangeSeekbar将移动

我写了像xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff" >

   <!--  <RelativeLayout 
      android:id="@+id/relative1" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_margin="10dp" >
    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        />



    </RelativeLayout> -->

     <RelativeLayout 
      android:id="@+id/relative2" 
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_below="@+id/relative1" 
      android:layout_margin="10dp">

         <LinearLayout 
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="vertical"
             android:layout_alignParentLeft="true"
             >

             <TextView
                 android:id="@+id/start"
                 android:layout_width="wrap_content"
                 android:layout_height="wrap_content"
                 android:paddingLeft="8dp"
                 android:text="Start"
                  android:paddingBottom="5dp"
                    android:textColor="#0072ff"
                    android:textStyle="bold" />

    <EditText
        android:id="@+id/edt_starttime"
        android:layout_width="50dp"
        android:layout_height="30dp"
          android:background="#0072ff"
          android:inputType="number"
          android:imeOptions="actionDone"/>
    </LinearLayout>


          <LinearLayout 
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:orientation="vertical"
             android:layout_alignParentRight="true"
             >
     <TextView 
          android:id="@+id/end"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:paddingLeft="10dp"
          android:paddingBottom="5dp"
          android:text="End"
          android:textColor="#0072ff"
          android:textStyle="bold"/>   
       <EditText
        android:id="@+id/edt_endtime"
        android:layout_width="50dp"
        android:layout_height="30dp"
        android:background="#0072ff"
        android:inputType="number"
        android:imeOptions="actionDone"/>

</LinearLayout>
     </RelativeLayout>


   <LinearLayout 
        android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/relative2"
    android:orientation="horizontal"
    android:layout_margin="10dp"
    android:id="@+id/layout">

   </LinearLayout>

</RelativeLayout>

我使用自定义RangeSeekbar类,如

RangeSeekBar.java

此课程是根据此link开发的 最后我的活动类是

MainActivity2.java

  public class MainActivity2 extends Activity 
    {
        //declaring widgets and variables...............

        WebView webView1;
        TextView start,end;
        EditText edt_starttime,edt_endtime;
        String url,edt_starttime1;
        View handler1;
        int minValue1;

        @Override

        //onCreate() starts............

        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);

            setContentView(R.layout.activity_main);

            //getting refrences of widgets.......

            webView1=(WebView)findViewById(R.id.webView1);

            start=(TextView)findViewById(R.id.start);

            end=(TextView)findViewById(R.id.end);

            edt_starttime=(EditText)findViewById(R.id.edt_starttime);

            edt_endtime=(EditText)findViewById(R.id.edt_endtime);

                    edt_starttime = (EditText) findViewById(R.id.edt_starttime);
            // edittext listenr starts...........




    //  editettxt start listener ends.........

            //editetxt end listener starts..............

            edt_endtime.setOnEditorActionListener(new OnEditorActionListener() 
            {

                @Override
                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
                {
                    // TODO Auto-generated method stub

                    if (actionId == EditorInfo.IME_ACTION_DONE)
                    {
                        Log.e("Ram san","jhgkfdjgh");

                        String edt_endtime1=edt_endtime.getText().toString();

                        if(edt_endtime1.length()!=0)
                        {

                            minValue1=Integer.parseInt(edt_endtime1);
                            Log.e("", ""+minValue1);

                        }

                           return true; // consume.
                        }                


                     // pass on to other listeners. 

                    return false;
                }
            });

           //edittext listeners ends.................       


            // create RangeSeekBar as Integer range between 20 and 75

            RangeSeekBar<Integer> seekBar = new RangeSeekBar<Integer>(0, 30, MainActivity2.this);
            seekBar.setLeft(25);
            seekBar.setOnRangeSeekBarChangeListener(new OnRangeSeekBarChangeListener<Integer>()
            {
                @Override
                 public void onRangeSeekBarValuesChanged(RangeSeekBar<?> bar, final Integer minValue, Integer maxValue) 
                 {



                 edt_starttime.setText(""+minValue);    
                 edt_endtime.setText(""+maxValue);

                    Log.e("values ", ""+ minValue + ", MAX=" + maxValue);
                  }
            });

            // add RangeSeekBar to pre-defined layout

            ViewGroup layout = (ViewGroup) findViewById(R.id.layout);
    //      layout.setP
            layout.addView(seekBar);
        }

        //onCreate() ends.................



    }

当edittext值基于移动rangeseekbar时,如何将EditText值设置为RangeSeekbar?

0 个答案:

没有答案