1

I want create a View the same Image. enter image description here Touch value on View: enter image description here

I using the solution create TextView and touch on TextView: This is layout xml: i create 6 TextViews to display value when Touch on Screen.

<LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">    
            <TextView
                android:id="@+id/txtPreSelect1"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"                   
                android:gravity="center"                   
                android:text="000"                     
                />

            <TextView
                android:id="@+id/txtPreSelect2"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="0"
              />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"                
            >    
            <TextView
                android:layout_width="200dp"
                android:layout_height="1dp"
                 />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtSelect1"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"
                android:layout_marginRight="@dimen/d_40"
                android:gravity="center"
                android:text="001"
               />

            <TextView
                android:id="@+id/txtSelect2"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="1"
               />
        </LinearLayout>    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center">

            <TextView
                android:layout_width="200dp"
                android:layout_height="1dp"
                />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/txtNextSelect1"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"
                android:layout_marginRight="@dimen/d_40"
                android:gravity="center"
                android:text="002"
               />

            <TextView
                android:id="@+id/txtNextSelect2"
                android:layout_width="@dimen/d_60"
                android:layout_height="match_parent"
                android:gravity="center"
                android:text="2"
                />
        </LinearLayout>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="1dp"
            />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"               
            android:gravity="center|right"
            android:orientation="horizontal">  

            <TextView
                android:id="@+id/btnCancel"
                android:layout_width="wrap_content"
                android:layout_height="40dp"                   
                android:gravity="center"
                android:text="@string/btnCancel"/>

            <TextView
                android:id="@+id/btnOK"
                android:layout_width="wrap_content"
                android:layout_height="40dp"                                    
                android:text="@string/btnOK"
               />
        </LinearLayout>
    </LinearLayout>

and i create event Touch on TextViews, to change value of Textview:

dialog.txtPreSelect1.setOnTouchListener {v: View, event: MotionEvent ->
        // Perform tasks here
        when (event.action)
        {
            MotionEvent.ACTION_DOWN ->{
                yValue=event.y
            }
            MotionEvent.ACTION_MOVE ->{
                val curentY=event.y
                if(curentY>yValue)
                {
                    if(curentY>yValue) {
                        yValue=curentY
                        var iStartValue=dialog.txtPreSelect1.text.toString().toInt() - iStep1
                        
                            dialog.txtPreSelect1.text = iStartValue.toString()
                       
                        iStartValue=iStartValue +iStep1
                        dialog.txtSelect1.text = iStartValue.toString()
                        iStartValue=iStartValue +iStep1                                                            dialog.txtNextSelect1.text = iStartValue.toString()
                        
                    }
                }
                else if(curentY<yValue)
                {
                    if(curentY<yValue) {
                        yValue=curentY
                        var iStartValue=dialog.txtPreSelect1.text.toString().toInt() + iStep1
                       
                         dialog.txtPreSelect1.text = iStartValue.toString()
                     
                        iStartValue += iStep1
                        dialog.txtSelect1.text = iStartValue.toString()                           
                        dialog.txtNextSelect1.text = iStartValue.toString()
                        
                    }

                }
            }
        }
        true
    }

How can create event move text the same image 2? Or Exist other View can process my work? Thank all.

Community
  • 1
  • 1
D T
  • 3,522
  • 7
  • 45
  • 89

2 Answers2

1

If I understand correctly your problem is in creating two views with lists, so you can touch and scroll them separately.

You can try to dive into this library that is quite similar what you are trying to reach: SingleDateAndTimePicker

aleksandrbel
  • 1,422
  • 3
  • 20
  • 38
0

My best guess is you want to use native component. You can use ListView but that would require much code than Number Picker. Number Picker is specifically designed to handle such situations.

Here in SO a Nice example can show you how to use it in dialog. Basically you need a LinearLayout with Horizontal Orientation and place two Number Picker inside it.

You can set MinValue and MaxValue with the help of java/kotlin like this:

numberPicker.setMaxValue(50);
numberPicker.setMinValue(1);

let me know if you have any query.

Rahul Khurana
  • 8,577
  • 7
  • 33
  • 60