Friday, February 27, 2015

Design Android Layout using Relative Layout

Field with text view and edit text as single field.

1.Textview on the left and edittext on the right side merged together as single field
2.Below are the code to create the above view

USE RELATIVE LAYOUT TO CREATE ABOVE VIEW

 <RelativeLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_weight="1" >

                        <TextView
                            android:id="@+id/ic_text_label49"
                            style="@style/CT_com_ic_edit_texview"
                            android:layout_width="50dp"
                            android:layout_height="40dp"
                            android:background="@drawable/rounded_textview"
                            android:text="@string/text_view49" />

                        <EditText
                            android:id="@+id/text49"
                            style="@style/CT_com_ictextbox"
                            android:layout_width="250dp"
                            android:layout_height="40dp"
                            android:layout_toRightOf="@+id/ic_text_label49"
                            android:background="@drawable/rounded_edittext"
                            android:imeOptions="actionNext"
                            android:singleLine="true" />
                    </RelativeLayout> 
 


TEXTVIEW STYLE AS FOLLOWS

<style name="CT_com_ic_edit_texview">
        <item name="android:textSize">18sp</item>
        <item name="android:gravity">center</item>
        <item name="android:layout_marginTop">20dp</item>
    </style> 
<style name="CT_com_ictextbox"> <item name="android:textSize">18sp</item> <item name="android:gravity">right|center_vertical</item> <item name="android:paddingRight">20dp</item> <item name="android:hint">.00</item> <item name="android:inputType">numberDecimal</item> <item name="android:layout_marginTop">20dp</item> <item name="android:imeOptions">actionNext</item> </style> 



NOW THE BACKGROUND VALUES ARE AS FOLLOWS 1.Background style for text view create a file name (rounded_textview)in my case and your own name and place the below code in that.
<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
    <!-- view background color -->
    <solid
        android:color="#D4E3F5" >
    </solid>
 
    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#2B65BC" >
    </stroke>
 
    <!-- If you want to add some padding -->
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"    >
    </padding>
 
    <!-- Here is the corner radius -->
    <corners
        android:topLeftRadius="6dp" 
        android:bottomLeftRadius="6dp">
    </corners>
 
</shape> 
 

2.Now the background style for edit text
create a file name (rounded_edittext)in my case and your own name and place the below code in that.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
 
    <!-- view border color and width -->
    <stroke
        android:width="1dp"
        android:color="#2B65BC" >
    </stroke>
 
    <!-- If you want to add some padding -->
    <padding
        android:left="4dp"
        android:top="4dp"
        android:right="4dp"
        android:bottom="4dp"    >
    </padding>
 
    <!-- Here is the corner radius -->
    <corners
        android:topRightRadius="6dp" 
        android:bottomRightRadius="6dp">
    </corners>
 <!-- view background color -->
   <solid
       android:color="#FFFFFF" >
   </solid>
</shape>

Wednesday, February 25, 2015

Android Conformation Dialogue


Conformation Dialogue with Yes&No button
1.This dialogue appears with two button
2.You can make use this to popup dialogue even for logout functionality

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to logout?")
  .setCancelable(false)
  .setPositiveButton("Yes",
  new DialogInterface.OnClickListener() {
   public void onClick(DialogInterface dialog, int id) {
           //Do what ever you want
   Toast.makeText(getApplicationContext(),
   "Successful",
   Toast.LENGTH_SHORT).show();
   }
   })
  .setNegativeButton("No",
  new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int id) {dialog.cancel();}});
   AlertDialog alert = builder.create();
   alert.show();

Dynamic textview on the Android Actionbar


Dynamic textview on the android action bar
1.Use the following inside onCreateOptionsMenu in main activity
2.Replace the strPersonName with your own text.

// creating dynamic textview to display user name on actionbar
  TextView tv = new TextView(this);
  tv.setText(strPersonName);
  tv.setTextColor(getResources().getColor(R.color.white));
  tv.setPadding(5, 0, 5, 0);
  tv.setTypeface(null, Typeface.BOLD);
  tv.setTextSize(14);

  menu.add(0, FILTER_ID, 1, strPersonName).setActionView(tv)
    .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

Android DatePicker sample code

Following are the code for date picker from edittext in fragment class.
1.Put the datepicker onclick method inside oncreate method.
2.Call the datepicker class and assign the selected value to the field in updatelabel method.
3.It is simple to implement and get the selected date

// Importing EditText
pDateofBirth = (EditText) rootView.findViewById(R.id.dp_pi_dob);

// datepicker onclick method
  pDateofBirth.setOnClickListener(new View.OnClickListener() {
   @Override
   public void onClick(View arg0) {
    // TODO Auto-generated method stub
    new DatePickerDialog(getActivity(), date, myCalendar
      .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH),
      myCalendar.get(Calendar.DAY_OF_MONTH)).show();

   }
  });

/* DatePicker event start */
 Calendar myCalendar = Calendar.getInstance();

 DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {
  @Override
  public void onDateSet(DatePicker view, int year, int monthOfYear,
    int dayOfMonth) {
   // TODO Auto-generated method stub
   myCalendar.set(Calendar.YEAR, year);
   myCalendar.set(Calendar.MONTH, monthOfYear);
   myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
   updateLabel();
  }
 };

 private void updateLabel() {
  String myFormat = "MM/dd/yyyy"; // In which you need put here
  SimpleDateFormat sdf = new SimpleDateFormat(myFormat, Locale.US);

  pDateofBirth.setText(sdf.format(myCalendar.getTime()));
 }

XML File

<EditText
                            android:id="@+id/dp_pi_dob"
                            style="@style/CT_com_containerNormalEditView"
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight=".95"
                            android:inputType="date"
                            android:onClick="selectDate"
                            android:focusable="false"
                            bootstrapbutton:be_roundedCorners="true" />

Tuesday, February 3, 2015

How to Ant Environment path set in mac

I am working in phonegap application. when i want to develop phonegap android blatform i want to set ant build path as environment variable. I tried various way to export the path. but i can't correctly set the ant both and then my friend referred just like this
Apples-MacBook-Pro:bin apple$ ant
-bash: ant: command not found
Apples-MacBook-Pro:bin apple$ cd
Apples-MacBook-Pro:~ apple$ which ant
Apples-MacBook-Pro:~ apple$ cd Documents/apache-ant-1.9.4/bin
Apples-MacBook-Pro:bin apple$ export PATH=$PATH:$PWD
Apples-MacBook-Pro:bin apple$ ant
Buildfile: build.xml does not exist!
Build failed
Apples-MacBook-Pro:bin apple$ cd
Apples-MacBook-Pro:~ apple$ ant
Buildfile: build.xml does not exist!
Build failed
Apples-MacBook-Pro:~ apple$ 

just try like this you can set easy.