Thursday 28 February 2013

Rating Bar Demo

Demo







1)ratingbar.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#EEA9B8"
    android:orientation="vertical" >

    <RatingBar
        android:id="@+id/ratingBar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="100dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="50dp"
        android:text="Show Rating" />

</LinearLayout>


2)Activity 


package com.venky.ratingbar;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RatingBar;
import android.widget.RatingBar.OnRatingBarChangeListener;
import android.widget.Toast;

public class RatingBarDemoActivity extends Activity {
      /** Called when the activity is first created. */

      RatingBar ratingBar;

      float ratingByUser;

      Button btnShowRating;

      @Override
      public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.ratingbar);

            ratingBar = (RatingBar) findViewById(R.id.ratingBar);

            ratingBar.setOnRatingBarChangeListener(new OnRatingBarChangeListener() {

                  @Override
                  public void onRatingChanged(RatingBar ratingBar, float rating,
                              boolean fromUser) {
                        // TODO Auto-generated method stub

                        ratingByUser = rating;
                  }
            });

            btnShowRating = (Button) findViewById(R.id.button);

            btnShowRating.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub

                        Toast.makeText(getApplicationContext(),
                                    "User Rating =>" + ratingByUser, Toast.LENGTH_SHORT)
                                    .show();

                  }
            });
      }
}



Wednesday 27 February 2013

Login Page Validations




Code:

            EditText edtEmail = (EditText) findViewById(R.id.edtEmail);
            EditText edtPassword = (EditText) findViewById(R.id.edtPassword);

            Button btnLogin = (Button) findViewById(R.id.btnLogIn);

            btnLogin.setOnClickListener(new OnClickListener() {

                  @Override
                  public void onClick(View v) {
                        // TODO Auto-generated method stub

                        String email = edtEmail.getText().toString().trim();
                        String password = edtPassword.getText().toString().trim();

                       
                        // Validatation part here

                        if (email.matches("")) {

                              edtEmail.setError("Enter Email Id");
                              edtPassword.setText("");

                              Toast.makeText(getApplicationContext(),
                                          "Please Enter Email Id", Toast.LENGTH_SHORT).show();

                        } else if (!(email
                                    .matches("[a-zA-Z0-9._-]+@[a-zA-Z]+\\.+[a-zA-Z]+"))) {

                              edtEmail.setError("Enter valid Email id");

                              edtEmail.setText("");
                              edtPassword.setText("");

                              Toast.makeText(getApplicationContext(),
                                          "Please Enter valid Email id", Toast.LENGTH_SHORT)
                                          .show();

                        } else if (password.length() < 5) {

                              edtPassword.setError("Enter Correct Password");

                              edtPassword.setText("");

                              Toast.makeText(getApplicationContext(),
                                          "Please Enter Correct Password", Toast.LENGTH_SHORT)
                                          .show();

                        } else {

                              //Success Logic
                              Toast.makeText(getApplicationContext(),
                                          email + "<=>" + password, Toast.LENGTH_SHORT)
                                          .show();
                        }

                  }
            });