Monday, May 7, 2012

Append two string one after each other

Android : Android is an open source software stack that include the operating system, middleware and key application along with set of API Libraries for writing mobile application that can shape the look,feel and function of mobile handsets.


3 technique is use for interapplication communication.


1. Notification
2. Intents
3. Content Provider
1-> Is a standard way in which mobile device traditionally alert users (by vibration,flash the device led etc)
2-> Provide mechanism for message passing within and between application
3-> It manage access to your application private database


Example.: Append two string one after each other.
main.xml
<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:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"/>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout1" android:orientation="vertical">
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:orientation="horizontal">
<TextView android:text="Enter Your Name:" android:id="@+id/lblfname" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/txtfname" android:layout_weight="1">
            <requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout3" android:orientation="horizontal">
<TextView android:text="Enter Your Last Name:" android:id="@+id/lbllname" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<EditText android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/txtlname" android:layout_weight="1">
           <requestFocus></requestFocus>
</EditText>
</LinearLayout>
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:orientation="horizontal">
 <RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal">
 <RadioButton android:layout_width="wrap_content" android:id="@+id/radio0" android:text="Appenddirectly" android:layout_height="wrap_content" android:checked="true"></RadioButton>
 <RadioButton android:layout_width="wrap_content" android:id="@+id/radio1" android:text="Appendindirectly" android:layout_height="wrap_content"></RadioButton>
</RadioGroup>
</LinearLayout>
</LinearLayout>
<Button android:text="Display" android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
</LinearLayout>
Example.java

package com.example;
import android.app.Activity;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class Example extends Activity{
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.main);
 Button b=(Button)findViewById(R.id.button1);
 final EditText fname=(EditText)findViewById(R.id.txtfname);
 final EditText lname=(EditText)findViewById(R.id.txtlname);
 final RadioGroup rdgp=(RadioGroup)findViewById(R.id.radioGroup1);
 b.setOnClickListener(new View.OnClickListener() {
 public void onClick(View v) {
 // TODO Auto-generated method stub
 int rdioid=rdgp.getCheckedRadioButtonId();
 final RadioButton rdbtn=(RadioButton)findViewById(rdioid);
 String rdnm=rdbtn.getText().toString();
 String txt,txt1,res=null;
 txt=fname.getText().toString();
 txt1=lname.getText().toString();
 Toast t=null;
 if (rdnm.equals("Appenddirectly"))
 {
 res=txt + " " +txt1;
 }
 else if(rdnm.equals("Appendindirectly"))
 {
 res=txt1+ " " + txt;
 }
 else
 {
 res="no name";
 }
 t=Toast.makeText(getApplicationContext(), res,Toast.LENGTH_LONG);
 t.setGravity(Gravity.BOTTOM,0, 0);
 t.show();
 }
 });
 }
}

output




No comments:

Post a Comment