Thursday, 23 August 2018

Xamarin Layout Movement

RANGE INPUT GENERATORXamarin Layout moment is a technique to move one interface to another interface.For example , user is login the system and after the login the user will get the homepage.Login and home page are separate interface.Application need to move from Login interface to homepage interface.




                
Xamarin application ,first gives the user the login layout, after the login has been verified ,the users will get home page layout. This is done by use intent and start activity.An activity of instant is created and the call start activity.Here we have two activity , we have to move between activity.
                       

This is the code , how and layout movement is done with start activity.  


  Android.Content.Intent i = new Android.Content.Intent(this, typeof(HomePage_Activity));
  StartActivity(i);

Please keep in the mind that you have to set content view for a particular activity at oncreate  method.Here is the full code.


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);

                                Android.Content.Intent i = new Android.Content.Intent(this, typeof(HomePage_Activity));
                              StartActivity(i);
                         }
                }
}



               Another aspect of this movement is , passing data.Activity need to pass some data to next
Activity. 

              For example , we are doing login, next we are going to the home page .The login page will pass homepage Activity about logged in user information ,so that home page can display particular user information. Putextra is a method  that can pass an extra value when we are moving to activity.



  Android.Content.Intent i = new Android.Content.Intent(this, typeof(HomePage_Activity));
 i.PutExtra("SessionID", "Your Session value");
  StartActivity(i);




Now , how homepage will receive the additional data sent by the login page. GetStringExtra method helps to retrieve the data.


 
string sessionid = Intent.GetStringExtra("SessionID") ?? "";


Xamarin EditText

EditText is very commonly used control for Android  platform. 
EditText means you can edit the text of the control.For example you are entering username and password to the system. EditText  accept username and password. You have to type your username and password to the EditText control. Below is the design code of EditText 

<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:hint="Please enter username"
        android:imeActionId="6"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="30sp"
        android:background="#FFFFFF"
         android:gravity="center" />

 


EditText control have some common property like 
  • id
  • layout_width
  • layout_height
  • hints
  • gravity
  • textcolor
  • singleLine
  • backgound


"
id" : Property is uniquely identified of the control. 
"text" : Text property accept text to be display in the control.
You can directly write the string or you can retrieve the string from string.xml file.Here is the example

directly write

<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:hint="Please enter username"
        android:imeActionId="6"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="30sp"
        android:background="#FFFFFF"
         android:gravity="center" 
     android:text="Hello World" />
 
text from string.Xml

<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:hint="Please enter username"
        android:imeActionId="6"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="30sp"
        android:background="#FFFFFF"
         android:gravity="center" 
     android:text="@string/UserName" />

As like other control Gravity property set the position of EditText. It can be placed center, button, top. Below is the example of to know how it can be placed at the top of its parent layout.

code
output

EditText has some variety of nature of accepting the text. It can accept a single line text. Here is the example

<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:hint="Please enter username"
        android:imeActionId="6"
        android:maxLines="1"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="30sp"
        android:background="#FFFFFF"
         android:gravity="center" 
     android:text="@string/UserName" />



EditText can accept multiple line of text, here is the example.

<EditText
       android:id="@+id/txt_user_name"
       android:layout_width="300dp"
       android:layout_height="wrap_content"
       android:lines="8"
       android:minLines="6"
       android:imeActionId="6"
       android:maxLines="5"
       android:singleLine="false"
       android:textColor="#000000"
       android:textSize="20sp"
       android:background="#FFFFFF"
      android:gravity="center" />



EditText connection password. Input type password property accept password.
Here is the example.

 
<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:lines="1"
        android:minLines="1"
        android:imeActionId="6"
        android:maxLines="1"
        android:inputType="textPassword"
        android:singleLine="true"
        android:textColor="#000000"
        android:textSize="20sp"
       android:background="#FFFFFF"
       android:gravity="center" />
 
 


You can design your  EditText in variety of format. You can the font size, colour of font background ect. Here is the example.Here text size is 30sp and background color is #CA5100 and fore color is #CA5100.
 
<EditText
        android:id="@+id/txt_user_name"
        android:layout_width="300dp"
        android:layout_height="wrap_content"
        android:minLines="1"
        android:imeActionId="1"
        android:maxLines="5"
        android:singleLine="false"
        android:textColor="#1C4475"
        android:textSize="30sp"
        android:background="#CA5100"
        android:gravity="center" />





EditText event handling is a very easy process. Below section show that how and even handle can be done. 
 
 
EditText btn2 = FindViewById(Resource.Id.txt_user_name);
btn2.Click += (object sender, EventArgs eventArgs) => 
{
     /* your statement */
};

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

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