Tuesday, March 4, 2014

How to view Sqlite data of ANDROID eclipse

Step 01
               Run the project
Step 02
              Then go to the DDMS mode
Step 03
           Go to file explore and go to the data folder
                           
Step 04
         Inside data folder there is another folder call data go there and find your project
       
Step 05
        inside your project go the the database folder and from there you can view your db file.click it and click the pull a file from a device
Step 06
   save the file and open it using SqLite Database Browser
        

Step 07
      Select your table name and view the data
           

download the  SQLite DataBase Browser http://sourceforge.net/projects/sqlitebrowser/






Monday, March 3, 2014

Create shapes using JAVA Console


Download the cord from
https://www.dropbox.com/s/bf0oo4nrdy9g58t/ShapesInJava.pdf

Work With Spinners in ANDROID

Step 01
Make an xml file in res->values name it as arrays

 <string-array name="douse">
        <item>Half</item>
        <item>One</item>
        <item>One and Half</item>
        <item>Two</item>
        <item>Two and half</item>
  </string-array>


Step 02
Cording of java file

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

public class Addpills extends Activity implements AdapterView.OnItemSelectedListener{

    Spinner spin_douse;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addpills);
        //load page
        spin_douse =(Spinner)findViewById(R.id.sp_I_douse_addpills);//get spinner to java from xml
        ArrayAdapter adapter_01 = ArrayAdapter.createFromResource(this, R.array.douse, android.R.layout.simple_spinner_item);

//add the string array which is on [res->values->arrays.xml] using arrayadapter to the spinner
        spin_douse.setAdapter(adapter_01);
        spin_douse.setOnItemSelectedListener(this);

}

@Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int i,
            long l) {

                //cord what happen when you select value on spinner
         // TODO Auto-generated method stub
        TextView res_text=(TextView)view;
        Toast.makeText(this, "You select "+res_text.getText(), Toast.LENGTH_SHORT).show();
        //make a message when click the selection
    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {
        // TODO Auto-generated method stub
       
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
   

}

How to use RadioButton Group in ANDROID




XML cord for radiobuttons and radiobutton group

 <RadioGroup
        android:id="@+id/rg_I_selectloging_activity_a"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        >

        <RadioButton
            android:id="@+id/rb_I_delear_activity_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Delear" />

        <RadioButton
            android:id="@+id/rb_I_rep_activity_a"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rep" />
    </RadioGroup>




 Java Cord for use radiobuttons   
      
// convert xml id of radiobutton group to java
 
  RadioGroup     rg=(RadioGroup)findViewById(R.id.rg_I_selectloging_activity_a);


loging=(Button)findViewById(R.id.bt_I_loging_activitymain_a);
 loging.setOnClickListener(new View.OnClickListener() {

final String value     =     ((RadioButton)findViewById(rg.getCheckedRadioButtonId())).getText().toString();     
 // get the selected radio buttons value as a string
                         if(value.equalsIgnoreCase("Delear")){
// check the string values is equal for another string value
                                 Intent openStartingPoint = new Intent("android.intent.action.DEALERMENU");
                                 startActivity(openStartingPoint);

// load a page

                           }
                else if(value.equalsIgnoreCase("Rep")){
                                Intent openStartingPoint = new Intent("android.intent.action.REPMENU");
                                startActivity(openStartingPoint);
                  
                }

});

---------------------------------------------------------------------------------------------------------------

if you want trigger some thing in radiobutton click
can use this cord

rg.setOnCheckedChangeListener(new OnCheckedChangeListener() 
        {
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch(checkedId){
                    case R.id.radio0:
                        // do operations specific to this selection
                    break;

                    case R.id.radio1:
                        // do operations specific to this selection
                    break;

                    case R.id.radio2:
                        // do operations specific to this selection
                    break;

                }


            }
        });
 


Pass Data Between two XML files in ANDROID using Java

In here i'm going to insert a text to edittext , and then click a button.Then the page move to another page and display the first text in the second page's text box

My first pages java file name is MainActivity.java and it's xml file name is activity_main.xml
in there I create a edittext(R.id.editText1) and a button (R.id.button1)

My secound pages java file name is Display.java it's xml file name is display.xml in there I creat a edittext(R.id.editText2)
----------------------------------------------------------------------------------------------------------
//this is the cord for the first java class (MainActivity.java)
package com.myapp.activity_01;


import android.inputmethodservice.ExtractEditText;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {
    public static String st="com.myapp.activity_01";//story my package name
   
    EditText e1;
    Button b1;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//
       
        e1=(EditText) findViewById(R.id.editText1);//get the  edittext xml  id  to java file
        b1=(Button) findViewById(R.id.button1);
     //get the  button xml  id  to java file
       b1.setOnClickListener(this);                           //set the on clicklistner
       
            }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        Intent i = new Intent(MainActivity.this, Display.class);
        Toast.makeText(getApplicationContext(), "Button Clicked! success!!!! ", Toast.LENGTH_LONG).show();
                //to display massage as the button is click
        String s=e1.getText().toString();//get the edittext's content to string variable


        i.putExtra(st,s);//pass the string value to the new activity
        startActivity(i);
//start new activity
       
    }

}


-------------------------------------------------------------------------------------------------------------------
//this is the cord for the first java class (Display.java)

package com.myapp.activity_01;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.EditText;

public class Display extends Activity {
   
    EditText e1;
   
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.display);
    //display the layout       
        e1=(EditText) findViewById(R.id.editText2);
//get the  edittext xml  id  to java file
        Intent i=getIntent();
        String s1=i.getStringExtra(MainActivity.st);
//get the pass string , to string varlable
        e1.setText(s1);//set the passed text value for the edit text
       
    }
   

}

Sunday, March 2, 2014

How to create custom Button in Android

How to create custom Button in Android

                                              


STEP 01
               create a xml file in drawable-hdip folder and insert this code ,here in call it as zcustomer button
                             <selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_pressed="true" >
  <shape>
  <solid
   android:color="#ef4444" />
  <stroke
   android:width="1dp"
   android:color="#FFFFFF" />
  <corners
   android:radius="3dp" />
  <padding
   android:left="10dp"
   android:top="10dp"
   android:right="10dp"
   android:bottom="10dp" />
  </shape>
 </item>
  <item>
  <shape>
  <gradient
   android:startColor="#ef4444"
   android:endColor="#992f2f"
   android:angle="270" />
  <stroke
   android:width="1dp"
   android:color="#FFFFFF" />
  <corners
   android:radius="3dp" />
  <padding
   android:left="10dp"
   android:top="10dp"
   android:right="10dp"
   android:bottom="10dp" />
 </shape>
 </item>
</selector>



STEP 02
              Add this cord for values->style.xml

   <style name="CustomStyleButton" parent="@android:style/Widget.Button">
     <item name="android:textSize">16sp</item>
     <item name="android:textStyle">bold</item>
     <item name="android:textColor">#dedfdc</item>
     <item name="android:gravity">center</item>
     <item name="android:shadowColor">#000000</item>
     <item name="android:shadowDx">1</item>
    <item name="android:shadowDy">1</item>
     <item name="android:shadowRadius">0.6</item>
     <item  name="android:background">@drawable/zcustomerbutton</item>
     <item name="android:padding">10dip</item>
    </style>



                                                      @drawable/zcustomerbutton is the name of the xml file i created on my drawable folder 
change the color values on your own using hex color values in http://www.color-hex.com/   
STEP 03      
              call the style in button     [add this cord of the xml button]
style="@style/CustomStyleButton"
  use the name that you given in the style.xml page