Friday, 24 August 2018

Xamarin Datepicker

RANGE INPUT GENERATORXamarin Datepicker control is a very powerful control to handle date. In software development, Date Picker play a helpful role to maintain organization data. Xamarin platform allow to drag and drop Date Piker control on  Xamarin Layout,but the problem is that , the control always visible full calendar mode on the view. You can also write on your Layout.axml file to display DatePiker control. But same problem , it will display full calendar on the view. 

              But in real life, we need a DatePicker to be open when required ,after you select the date,it should be closed.DatePicker will update corresponding value to the  particular EditText box or a Textview.

Here is the step , how to do this.

Here we have taken a Edittext and a Imageview. We have added an image from drawable folder.Below is the axml code design.


xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="horizontal"
        android:background="#194575">


<TextView
       android:layout_width="150dp"
       android:layout_height="wrap_content"
       android:text="Date"
      android:textSize="15sp"
      android:textColor="#ffffff"
/>


<EditText
     android:layout_width="150dp"
     android:layout_height="wrap_content"
     android:id="@+id/editText"
     android:textColor="#000000"
     android:textSize="15sp"
     android:background="#FFFFFF" />

<ImageView
    android:id="@+id/btlnCalender"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/calender" />

</LinearLayout>




We have handle the image click event and dynamically created a datepicker instance. Here is the code


ImageView imgView = FindViewById(Resource.Id.btlnCalender);
imgView.Click += (sender, e) =>
{
         System.DateTime today = System.DateTime.Today;
         DatePickerDialog dialog = new DatePickerDialog(this, OnDateSet, today.Year, today.Month - 1, today.Day);
         dialog.DatePicker.MinDate = today.Millisecond;
         dialog.Show();
};


Here is the full code of this activity


using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;

namespace App5
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class LoginActivity : AppCompatActivity
{
           protected override void OnCreate(Bundle savedInstanceState)
             {
               base.OnCreate(savedInstanceState);

               SetContentView(Resource.Layout.activity_main);

               ImageView imgView = FindViewById(Resource.Id.btlnCalender);

               imgView.Click += (sender, e) =>
                {
                           System.DateTime today = System.DateTime.Today;
                            DatePickerDialog dialog = new DatePickerDialog(this, OnDateSet, today.Year, today.Month - 1, today.Day);
                           dialog.DatePicker.MinDate = today.Millisecond;
                            dialog.Show();
                  };
}

public void OnDateSet(object sender, DatePickerDialog.DateSetEventArgs e)
{
            EditText objDate = FindViewById(Resource.Id.editText);
             objDate.Text = e.Date.ToShortDateString();
        }
   }
}


Below is the output




Xamarin Textview

RANGE INPUT GENERATORXmarin TextView is a control for displaying text in Xmarin Layout. TextView accept text from string.xml file or you can directly write the text in the TextView control. 

Here is example of TextView displaying text directly. 


<TextView
          android:text="Hellow World"
         android:layout_width="match_parent"
          android:layout_height="wrap_content"
         android:id="@+id/textView1"
         android:textColor="#ffffff"/>


Here is the example of TextView displaying text from string.xml. 


string.xml

<resources>
     <string name="hellow_world">Hellow World</string>
</resources>

Here is the control

<TextView
       android:text="@string/hellow_world"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:id="@+id/textView1"
        android:textColor="#ffffff"/>

The TextView is fully Programmable, you can display text from program also. Here is the example.

Here is the control
<TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/textView1"
        android:textColor="#ffffff"/>

Here is program source code
 
TextView txtNm = FindViewById(Resource.Id.textView1);
txtNm.Text="Hellow World";

Here is the output , how all three above look like

 


If TextView comes with variety of property and options.TextView can be single line or multi line.Setting  Single line property to false and line number control the number of line and text line in the Layout.


Here is the Example of a single line TextView 

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textView1"
android:singleLine="true"
android:textColor="#ffffff"/>



Here hair is the example of multi line  TextView.

 
<TextView
android:layout_width="match_parent"
android:layout_height="100dp"
android:id="@+id/textView1"
android:singleLine="false"
android:maxLines="5"
android:textColor="#ffffff"
android:text="Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World Hellow World" />





TextView text size can be control and fore color back ground color also can be control. Here is the example textsize to 30 and back
ground color yellow and fore color to red.


<TextView
          android:layout_width="match_parent"
          android:layout_height="100dp"
          android:id="@+id/textView1"
          android:singleLine="true"
          android:textColor="#F0C94C"
          android:textSize="30dp"
          android:text="Hellow World"
          android:background="#DB483B"/>



 

TextView display position can be seat from gravity property.Position  of the control Top ,Bottom ,Left, Right of its  parent can be handled. 


Here is the example


<TextView
      android:layout_width="match_parent"
      android:layout_height="100dp"
      android:id="@+id/textView1"
      android:singleLine="true"
      android:textSize="15dp"
      android:text="Hellow World"
      android:background="#DB483B"
      android:gravity="center"/>






TextView event can be handled by event handler method. Here is the example of  how click event can we handle of a text to control.


Layout File

<TextView
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:id="@+id/textView1"
        android:singleLine="true"
        android:textSize="15dp"
        android:text="Hellow World"
        android:background="#DB483B"
        android:gravity="center"/>

Activity

 
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;

namespace App5
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class LoginActivity : AppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);

SetContentView(Resource.Layout.activity_main);

TextView txtNm = FindViewById(Resource.Id.textView1);
txtNm.Click += (sender, e) =>
{

         Android.App.AlertDialog.Builder dialog = new Android.App.AlertDialog.Builder(this);
         Android.App.AlertDialog alert = dialog.Create();
         alert.SetTitle("Hi");
         alert.SetMessage("You have Clicked TextView");
          alert.SetButton("OK", (c, ev) =>
          {
                  });
                alert.Show();
          };
       }
   }
}

Output:

 

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...