Rapid Subscribe Android App

Rapid Subscribe Android App
Rapid Subscriber

Recent Posts

Create a Wheel View Dialog in Android (Scroll view in Dialog Box)

In this post, we will show you how to create a Wheel View (Scroll View in Dialog Box) in Android



By creating a Wheel View Dialog in Android, you can add some values by clicking on a button and select from those values and then set it on somewhere else.

To create a Wheel View, we add a Wheel View library in our app-level Gradle File.

app-level Gradle file
 implementation 'com.wx.wheelview:wheelview:1.3.3'  

Then add a TextView in .xml file

 <?xml version="1.0" encoding="utf-8"?>  
 <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:app="http://schemas.android.com/apk/res-auto"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   tools:context=".SampleActivity">  
   <TextView  
     android:layout_width="wrap_content"  
     android:layout_height="wrap_content"  
     android:text="Wheel View Sample Dialog"  
     android:gravity="center_horizontal"  
     android:textSize="36sp"  
     android:id="@+id/wheel_view_tv"/>  
 </android.support.constraint.ConstraintLayout>  

Then create an ArrayList and a Wheel View Dialog method in Java file and use that dialog method in on click listener of TextView.


 package studio.harpreet.sampleproject;  
 import android.graphics.Color;  
 import android.support.v7.app.AppCompatActivity;  
 import android.os.Bundle;  
 import android.view.View;  
 import android.widget.TextView;  
 import android.widget.Toast;  
 import com.wx.wheelview.widget.WheelView;  
 import com.wx.wheelview.widget.WheelViewDialog;  
 import java.util.ArrayList;  
 public class SampleActivity extends AppCompatActivity {  
   TextView tv;  
   @Override  
   protected void onCreate(Bundle savedInstanceState) {  
     super.onCreate(savedInstanceState);  
     setContentView(R.layout.activity_sample2);  
     tv = findViewById(R.id.wheel_view_tv);  
     tv.setOnClickListener(new View.OnClickListener() {  
       @Override  
       public void onClick(View view) {  
         show_wheelView();  
       }  
     });  
   }  
   private void show_wheelView()  
   {  
     WheelViewDialog dialog = new WheelViewDialog(this);  
     dialog.setTitle("Dialog Title")  
         .setItems(wheel_count())  
         .setDialogStyle(Color.parseColor("#6699ff"))  
         .setCount(3)  
         .setLoop(true)  
         .setButtonText("Ok")  
         .setOnDialogItemClickListener(new WheelViewDialog.OnDialogItemClickListener() {  
           @Override  
           public void onItemClick(int position, String s) {  
             Toast.makeText(SampleActivity.this, "You Click on "+s+" Value", Toast.LENGTH_SHORT).show();  
           }  
         })  
         .show();  
   }  
   private ArrayList<String> wheel_count()  
   {  
     ArrayList<String> arraylist = new ArrayList<>();  
     arraylist.add("5");  
     arraylist.add("10");  
     arraylist.add("15");  
     arraylist.add("20");  
     arraylist.add("25");  
     arraylist.add("30");  
     arraylist.add("35");  
     arraylist.add("40");  
     arraylist.add("45");  
     arraylist.add("50");  
     return arraylist;  
   }  
 }  

Now, when we run our app and click on text view then our Wheel View dialog is shown and Working perfectly.


 
Follow us for more posts like this, 
Subscribe to Harpreet studio on Youtube  
Like Harpreet Studio on Facebook  
Follow me on Instagram 

No comments