Monday, 18 February 2013

How To Use Various Font(like Marathi) In Your App

8 comments
Android doesn't support various fonts like Marathi so this tutorial gives you idea about how to use various font like Marathi in your app.So you can display your data in various languages using the font combination in your app.

Step1)First you have to download the .ttf file like (akshar.ttf for marathi font) which will be used for converting your text according to this font.

Step2)After Downloading this file,You have to copy this file and paste in your asset folder.

Step3)Suppose you take a text view to display to your data which is stored in your string.xml,then you have to write this following code for displaying this data with this font format.

           a)  TextView  t1 = (TextView) findViewById(R.id.t1); 

           b)  Typeface tf = Typeface.createFromAsset(getAssets(), "akshar.ttf");
                  t1.setTypeface(tf, Typeface.BOLD);


 Step4)Next,You have to write this following in your XML.   
       
                  <TextView
                    android:id="@+id/t1"
                   android:layout_width="fill_parent"
                   android:layout_height="fill_parent"
                   android:text="@string/sindhu"
                   android:textColor="#000000"
                   android:textSize="6pt" />


Step5)Then you write you string.xml with the following.
              
             <string name="sindhu">सिंधुदुर्ग जिल्हा हा १५.३७ आणि १६.४० उत्तर अक्षवृत्त व ७३.१९ आणि     ७४.१८  पूर्व रेखावृत्त या दरम्यान वसलेला आहे. 

Thank u....
 
Read full post »

Wednesday, 13 February 2013

Code To Start Camera with Build-in Intent

0 comments
This code will show you how to start camera using intent and save the image to the file name.

Step1)Private constants & variable uses in the class:

 private static int TAKE_PIC = 1;
 private Uri FileUri;
 
Step2)Once the code is run, the camera pops up, just take your photo, and click on “Done” button on the screen. That would close the camera app and returns to your own App.
          
  private void ClickPhoto() {
  Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
  File file = new File(Environment.getExternalStorageDirectory(), "img1.jpg");
 
  FileUri = Uri.fromFile(file);
  intent.putExtra(MediaStore.EXTRA_OUTPUT, FileUri);
  startActivityForResult(intent, TAKE_PICTURE);
 
}

Step3)You need to override the onActivityResult to handle when the camera returns to your app:
                         
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data){
 
  if (requestCode == TAKE_PIC){
   //do whatever you want
  }
 
 }

 Thank U....
Read full post »

Sunday, 10 February 2013

How To Add Spinner dynamically on AlertDialog-Box

0 comments
Sometimes you face the problem regarding adding spinner on AlertdialogBox.So dont worry I give
the solution here:

Step1)Create a method name ViewDemo() and call it in your onCreate() method.

Setp2)Then Add this following

    AlertDialog.Builder Dialog = new AlertDialog.Builder(this);
    Dialog.setTitle("Select Option");

     LayoutInflater li = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
     View dialogView = li.inflate(R.layout.option, null);
     Dialog.setView(dialogView);

      Dialog.setPositiveButton("Ok",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });

      Dialog.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                    }
                });
        Dialog.show();
        Spinner spinnercategory = (Spinner) dialogView
                .findViewById(R.id.viewSpin);
        ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
                this, R.array.category, android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinnercategory.setAdapter(adapter);

        spinnercategory.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> parent, View arg1,
                    int arg2, long arg3) {
                //String selItem = parent.getSelectedItem().toString();
            }

            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }
        });

    }

Step3)Then Write the xml file option.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:orientation="vertical"
    android:paddingLeft="10dip" >

    <Spinner
        android:id="@+id/viewSpin"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:prompt="@array/category" />

</LinearLayout>

Step4)At last You create an array of option in val/array.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="category">
        <item>A +VE</item>
        <item>A -VE</item>
        <item>B +VE</item>
        <item>B -VE</item>
        <item>O +VE</item>
        <item>O -VE</item>
         <item>AB +VE</item>
        <item>AB -VE</item>
       
        </string-array>
</resources>

For Download Source Click Here

    Thanks..
Read full post »

Saturday, 9 February 2013

How To Add Tabs In Android

0 comments
 This tutorial is based on adding tabs in your activity in android.Also you give background
  image to your tabs.So follows the step:

Step1) First you add the following code in your Xml file,This will have three basic components
                             a)Tab-Host     b)Frame-layout     c)Tab-widget

        tab_layout.xml

        <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:orientation="vertical"
        android:layout_weight="1">

        <TabHost
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >

                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="0dip"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1"
                    android:editable="false"
                    android:textSize="10sp" />

                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />
            </LinearLayout>
        </TabHost>
    </LinearLayout>         

 Step2)          
                  Then coming to the Java file you add the following code: 

          TabDemo.class 

        a)  Tabhost tabHost = (TabHost)findViewById(android.R.id.tabhost);

        b) Add the tabspec to your Tabhost

             TabSpec firstTabSpec = tabHost.newTabSpec("Type1");
             TabSpec secndTabSpec = tabHost.newTabSpec("Type2");


        c)Set the action for the tabspec and background image for spec.
        
             
//Type1
              Intent i1=new Intent(ClassActivity.this,Type1Activity.class);
              firstTabSpec.setIndicator("",getResources().getDrawable(R.drawable.type1)).setContent(i1);
          
              //Type2
              Intent i2=new Intent(ClassActivity.this,Type2Activity.class);
              secndTabSpec.setIndicator("",getResources().getDrawable(R.drawable.type2)).setContent(i2);

                    
         d)Add the tab to the tabhost.
 
            
  tabHost.addTab(firstTabSpec);
               tabHost.addTab(secondTabSpec);




   Thnks...
          

   
Read full post »

Friday, 8 February 2013

How to add view dynamically on AlertDialogBox

3 comments
 This tutorial relates to the adding view(such as text view,edit-text,etc) to the Alert dialog
 dynamically in a java code.This will be used for creating the log in screen with Alert dialog.

Step1)First,create the object of the Alert Dialog builder as follows:

              AlertDialog.Builder alert = new AlertDialog.Builder(this);
              alert.setTitle("Login Screen");

Step2) After you create object of the views you want and add properties to them with following:
 
             LinearLayout lila1 = new LinearLayout(this);
             lila1.setOrientation(1);
             TextView t1 = new TextView(this);
             TextView t2 = new TextView(this);
             t1.setText("Enter your Login ID:");
             t1.setTextColor(Color.parseColor("#FFFFFF"));
             input1 = new EditText(this);
             t2.setText("Enter your Password:");
             t2.setTextColor(Color.parseColor("#FFFFFF"));
             input2 = new EditText(this);
             input2.setInputType(0x00000081);

Step3)Then,you add the view and set the view with the following:

             lila1.addView(t1);
             lila1.addView(input1);
             lila1.addView(t2);
             lila1.addView(input2);
             alert.setView(lila1);

Step4) Last,To add the buttons to the alert dialog you do the following:

              alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int whichButton) {

               }
              });

              alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int whichButton) {
                    
                }
                });

 Step5)    
                alert.show();

Thanks..

                  
            
Read full post »

Creating a dynamic row in TableLayout..

4 comments

All of you know to add a no.of rows in Table-layout by using XML.but here i will provide you the
guideline for generating rows dynamically in your android code.


Step:1)First of all you add Table-layout in your XML file.like following

         <TableLayout
                       android:id="@+id/tbl_product"
                       android:layout_width="fill_parent"
                      android:layout_height="wrap_content" >

        </TableLayout>


Step:2)Then u add the follwing code in your java file.


A) First,you set up the control for table layout.

         TableLayout prodlist = (Table Layout) findViewById(R.id.tbl_product);


B) Second,you will create a method name display(). in that u create a row using follwing:

        void display(String id, String name) {

        Table Row tr2 = new Table Row(this);
        tr2.layout(0, 0, 0, 0);


C) Third,you will create a two text view which will be added in that above row and set the argument value of display() method to that text view.


First text-view:


      TextView lblid = new TextView(this);
        lblid.setText("" + id);
        lblid.setTextColor(Color.BLACK);
        lblid.setTextSize((float) 11.5);
        lblid.setTypeface(null, 1);
        lblid.setBackgroundColor(Color.TRANSPARENT);
        lblid.setPadding(30, 0, 0, 0);


        tr2.setPadding(0, 1, 0, 0);
        tr2.addView(lblid);


Second text-view:


      TextView lblname = new TextView(this);
        lblname.setText("" + name);
        lblname.setTextColor(Color.BLACK);
        lblname.setTextSize((float) 11.5);
        lblname.setTypeface(null, 1);
        lblname.setBackgroundColor(Color.TRANSPARENT);
        lblname.setPadding(30, 0, 20, 0);
        tr2.setPadding(0, 1, 0, 1);
        tr2.addView(lblname);

 

Step:3)

Next most important thing is add the table row to the tableLayout by the following:


       prodlist.addView(tr2, new TableLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));



Thanks...
Read full post »

How to set up android developement environment

0 comments

 Here you can get step by step description of how to set up the android development  environment.

Basic Tools:
                  1)Windows machine(you also use mac/Linux)
                  2)Eclipse IDE for Java Developer(With ADT Plugins)
                  3)JDK(updated)
                  4)Android SDK
                
Step1)
                     First step you download ADT Bundle For Windows From here:

                     link: http://developer.android.com/sdk/index.html

                    With a single download, the ADT Bundle includes everything
                     you need to begin developing apps:
                      -Eclipse + ADT plugin
                      -Android SDK Tools
                      -Android Platform-tools
                      -The latest Android platform
                      -The latest Android system image for the emulator
Step2)
                    Next Step is double-Click On the SDK Manager.exe it automatically 
                    starts to download all packages includes emulators,google-api,etc
                    (from android1.6-onwords).

Step3)
                   Last Step is Launch the emulator and starts developing..

Thanks..
Read full post »
 

Copyright © Unique Android Tutorial.. Design by Free CSS Templates | Blogger Theme by BTDesigner | Powered by Blogger