Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Friday, December 7, 2012

ScrollView with Button on Bottom in Android


ScrollView with Button on Bottom in Android

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="wrap_content" android:layout_width="fill_parent">
     <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="This text view should act as header  " />
     <ScrollView android:layout_marginBottom="50dip" android:id="@+id/ScrollView01" android:layout_height="wrap_content" android:layout_width="fill_parent">
          <RadioGroup android:id="@+id/RadioGroup01" android:layout_width="wrap_content" android:layout_height="wrap_content">
               <RadioButton android:id="@+id/RadioButton01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />
               <RadioButton android:id="@+id/RadioButton11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Radio Button....." />       
          </RadioGroup>
     </ScrollView>
     <RelativeLayout android:layout_marginTop="-50dip" android:gravity="bottom" android:layout_height="wrap_content" android:layout_width="fill_parent">
        <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="1">
         <TableRow>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="One"/>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Two" android:layout_gravity="center_vertical"/>
        <Button android:id="@+id/Button01" android:layout_height="wrap_content" android:layout_width="wrap_content" android:text="Three" android:layout_gravity="right"/>
      </TableRow>
      </TableLayout>
     </RelativeLayout>
</LinearLayout>

Sunday, November 18, 2012

Recieve SMS and show it in Activity as DialogBox

Recieve SMS and show it in Activity as DialogBox


Source Code

Tuesday, October 23, 2012

How To Install Android SDK


How To Install Android SDK
Here you will get complete guide how to install android SDK on you computer to get started will android. Installing android is not a big deal but there are 3 to 4 things to install to get started and that's what makes android installation complicated for some user.

Step 1
For Android SDK you must have Windows XP, Windows Vista or Windows 7.

Step 2
Install JDK or JRE



http://www.oracle.com/technetwork/java/javase/downloads/index.html

Step 3
Install Eclipse





For 32 bit
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.6.1-201009090800/eclipse-SDK-3.6.1-win32.zip

For 64 bit
http://www.eclipse.org/downloads/download.php?file=/eclipse/downloads/drops/R-3.6.1-201009090800/eclipse-SDK-3.6.1-win32-x86_64.zip


Step 4
Install Android SDK



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

Step 5

http://developer.android.com/sdk/eclipse-adt.html

After installing Eclipse and Android SDK you must install Android Development Tools (ADT) Plugin to built android project in eclipse.

1- Start Eclipse then Help -> Install New Software
2- Click Add, in the top-right corner.
3- In the Add Repository dialog that appears, type  following URL for the Location:

    https://dl-ssl.google.com/android/eclipse/

4-In the Available Software dialog, select the checkbox next to Developer Tools and click Next.
5-In the next window, you'll see a list of the tools to be downloaded. Click Next.
6-Read and accept the license agreements, then click Finish.
7-When the installation completes, restart Eclipse

Step 6
Open Eclipse then Windows . If you will see Android SDK and AVD Manager then it mean that you can now start development in android
If you don't see Android Project in New then go to Other and select Android Project.
After Selecting Android Project if Built Target is empty then go to Windows ->  Preferences and select android then locate you installed SDK in SDK location 

Click here to get all links that will help you to install android SDK


Monday, October 22, 2012

Android Grid View


In java file
GirdView_Act.java


package GirdView.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;

public class GirdView_Act extends Activity implements
AdapterView.OnItemSelectedListener {
TextView selection;
String[] items = { "one", "two", "three", "four", "five", "six", "seven",
"eight", "nine", "ten", "eleven", "thirteen", "fouteen", "fifteen",
"sixteen", "seventeen", "eighteen", "ninteen", "twenty",
"twenty one", "twenty two", "twenty three", "twenty four",
"twenty five", "twenty six", "twenty seven", "twenty eight",
"twenty nine", "thirty", "one", "two", "three", "four", "five",
"six", "seven", "eight", "nine", "ten", "eleven", "thirteen",
"fouteen", "fifteen", "sixteen", "seventeen", "eighteen",
"ninteen", "twenty", "twenty one", "twenty two", "twenty three",
"twenty four", "twenty five", "twenty six", "twenty seven",
"twenty eight", "twenty nine", "thirty", };

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
GridView g = (GridView) findViewById(R.id.grid);
g.setAdapter(new FunnyLookingAdapter(this,
android.R.layout.simple_list_item_1, items));
g.setOnItemSelectedListener(this);
}

public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
selection.setText(items[position]);
}

public void onNothingSelected(AdapterView<?> parent) {
selection.setText("");
}

private class FunnyLookingAdapter extends ArrayAdapter {
Context ctxt;

@SuppressWarnings("unchecked")
FunnyLookingAdapter(Context ctxt, int resource, String[] items) {
super(ctxt, resource, items);
this.ctxt = ctxt;
}

public View getView(final int position, View convertView,
ViewGroup parent) {
TextView label = (TextView) convertView;
if (convertView == null) {
convertView = new TextView(ctxt);
label = (TextView) convertView;
}
label.setText(items[position]);
return (convertView);
}
}
}

In xml files
main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<GridView
android:id="@+id/grid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:verticalSpacing="35px"
android:horizontalSpacing="5px"
android:numColumns="auto_fit"
android:columnWidth="100px"
android:stretchMode="columnWidth"
android:gravity="center"
/>
</LinearLayout>



Android List View ( using EfficientAdapter)


In java file


package ListView.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class my_listview extends Activity {
ListView itemList = null;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listview2);
// TODO Auto-generated method stub
itemList = (ListView) findViewById(R.id.itemList);
itemList.setAdapter(new EfficientAdapter(this));
}

String[] Qitems = {"Q1", "Q2", "Q3", "Q4", "Q5", "Q6", "Q7", "Q8", "Q9", "Q10", "Q11", "Q12", "Q13", "Q14", "Q15"};

String[] Aitems = { "Ans1", "Ans2", "Ans3", "Ans4", "Ans5", "Ans6", "Ans7", "Ans8", "Ans9", "Ans10", "Ans11", "Ans12", "Ans13", "Ans14", "Ans15" };

public class EfficientAdapter extends BaseAdapter {
private LayoutInflater mInflater;
public Context ctxt;

public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
this.ctxt = context;
}

public int getCount() {
return Qitems.length;
}

public Object getItem(int position) {
return position;
}

public long getItemId(int position) {
return position;
}


public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;

if (convertView == null) {
convertView = mInflater.inflate(R.layout.custom_listview, null);
holder = new ViewHolder();
holder.titletxt = (TextView) convertView.findViewById(R.id.titletxt);
holder.ratingtxt = (TextView) convertView.findViewById(R.id.ratingtxt);

convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.ratingtxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), Aitems[position],Toast.LENGTH_LONG).show();
}
});

holder.titletxt.setText(Qitems[position]);
holder.ratingtxt.setText("Answer");

return convertView;
}

class ViewHolder {
TextView titletxt;
TextView ratingtxt;

}
}
}

In first xml file (.xml)

custom_listview.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_height="wrap_content"
android:layout_width="wrap_content">
<TextView
android:id="@+id/titletxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:textSize="18sp"
android:text="fasdsadsad"
android:textStyle="bold">
</TextView>
<TextView
android:id="@+id/ratingtxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10px"
android:textColor="#ffffff"
android:text="123"
android:layout_below="@+id/titletxt"
android:textSize="10sp">
</TextView>
</RelativeLayout>
</LinearLayout>

In second xml file (.xml)

listview2

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/ImageView1"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="@drawable/icon">
</ImageView>
<ListView
android:layout_below="@+id/ImageView1"
android:id="@+id/itemList"
android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:background="#20000000">
</ListView>
</RelativeLayout>

Note :- Question and Answers in String Qitem and Aitems are just for example.



Android List View ( Simple ListView using ArrayAdapter)


In java file( .java)


package ListView_Pkge.app;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class ListView_Acty extends ListActivity {

String[] Qitems = {
"Q1:What are the advantages of Object Oriented Programming Languages (OOPL)?",
"Q2:How do you express an ‘is a’ relationship and a ‘has a’ relationship or explain inheritance and composition? What is the difference between composition and aggregation?",
"Q3:What do you mean by polymorphism, inheritance, encapsulation, and dynamic binding?",
"Q4:What is the difference between an abstract class and an interface and when should you use them?",
"Q5:How would you communicate between applets and servlets?",
"Q6:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q7:Explain the RMI architecture?",
"Q8:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q9:How will you pass parameters in RMI?",
"Q10:What is the difference between final, finally and finalize() in Java?",
"Q11:Why use LDAP when you can do the same with relational database (RDBMS)?",
"Q12:Explain the RMI architecture?",
"Q13:What is a remote object? Why should we extend UnicastRemoteObject?",
"Q14:How will you pass parameters in RMI?",
"Q15:What is the difference between final, finally and finalize() in Java?"};

String[] Aitems = {  "Ans1","Ans2","Ans3","Ans4","Ans5","Ans6","Ans7","Ans8","Ans9","Ans10","Ans11","Ans12","Ans13","Ans14","Ans15"};
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.listview2);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Qitems));
}

public void onListItemClick(ListView parent, View v, int position, long id) {
Toast.makeText(this, Aitems[position], Toast.LENGTH_LONG).show();
}
}


In XML file ( .xml)


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="@+id/selection"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
/>
</LinearLayout>


Note :- Question and Answers in String Qitem and Aitems are just for example.
Source Code




Inside Android Manifest



The foundation for any Android application is the manifest file, AndroidManifest.xml in 
the root of your project. Here is where you declare what is inside your application—the activities, the services, and so on. You also indicate how these pieces attach themselves to the overall Android system; for example, you indicate which activity (or activities) should appear on the device’s main menu. 
When you create your application, a starter manifest will be generated for you
automatically. For a simple application, offering a single activity and nothing else, the autogenerated manifest will probably work out fine, or perhaps require a few minor modifications. On the other end of the spectrum, the manifest file for the Android API demo suite is more than 1,000 lines long. Your production  Android applications will probably fall somewhere in the middle.

Underneath the Manifest element


  • user permission elements: Indicate the permissions your application will need in order to function properly.
  • permission elements: Declare permissions that activities or services might require other applications to hold in order to use your application’s data or logic.
  • instrumentation elements: Indicate code that should be invoked on key system events, such as starting up activities, for the purposes of logging or monitoring.
  • uses-library elements: Hook in optional Android components, such as mapping services.
  • uses-sdk element: Indicates for which version of the Android SDK the application was built.
  • application element: Defines the guts of the application that the manifest describes.

Here’s an example:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commonsware.android">
<uses-permission
android:name="android.permission.ACCESS_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_GPS" />
<uses-permission
android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission
android:name="android.permission.ACCESS_CELL_ID" />
<application>
...
</application>
</manifest>
In this example, the manifest has uses permission elements to indicate some device capabilities the application will need—in this case, permissions to allow the application to determine its current location. The contents of the application element will describe the activities, services, and whatnot that make up the bulk of the application itself.

Inside Android Project



In this post I will share that what is inside the android project. When you open android project you will see many files and folder in it.

Src
In this folder you will see java files. Whatever you will work in java you will do in this folder.

Gen
This is generated java file and you will see R.java file in this folder. There is nothing to do with this file when you open this file you will see on the top it says that DO NOT MODIFY. Whenever you will add components or anything in android using XML then it will added in this folder ( source code will be generated In this file) and after adding component to this folder you can easily bind that component with java (through R.java file) and can do whatever you like to do with that component.

Assets
A folder that holds other static files you wish packaged with the application for deployment onto the device.

Res
In this resource folder you will see drawable-hdpi, drawable-ldpi, drawable-mdpi, layout and values folder. Let’s talk about layout first.  You will see main.xml file in layout and in this file you can make layout or you can say UI of android using XML. In Values folder there is string.xml file. This file help to make anything global ( means it can be use everywhere in application). If your project name is ABC and you want to use it anywhere in your project just add you project name ( p_name = ABC) now whenever you will call p_name you will see ABC and can easily change it(no need to change this name everywhere). Now let talk about drawable. If you want to add any picture in you project you will insert in this folder. But why three folder of drawable? High resolution pictures goes in hdpi, medium resolution in mdpi and low in ldpi.

Manifest.xml
An XML file describing the application being built and which components—activities, services, and so on—are being supplied by that application.

Default.properties and local.properties
Property files used by the Ant build script.

Res/drawable/:For images (PNG, JPEG, etc.).
Res/layout/:For XML-based UI layout specifications.
Res/menu/:For XML-based menu specifications.
Res/raw/:For general-purpose files (e.g., a CSV file of account
information).
Res/values/:For strings, dimensions, and the like.
Res/xml/:For other general-purpose XML files you wish to ship.