tag:blogger.com,1999:blog-11918253750549823222024-03-28T02:48:24.530-07:00Android BeginnersAbu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-1191825375054982322.post-7027829440913998982011-12-16T12:01:00.000-08:002011-12-16T12:01:50.377-08:00Android multiple screen same layout<div> It is very import use common layout for multiple screen if is possible. Now I show you a simple example of use single layout in multiple screen. And also manipulate them.<br />
</div><br />
<br><br />
<div style="border:1px solid black; width:250px; height:150px; float:left;"> <div style="padding:5px 0px 0px 20px;" > Screen A<br />
</div> <div style="padding:5px 0px 0px 10px;" > Name: <input type="text" width=100><br />
</div> <div style="padding:5px 0px 0px 12px;"> Email: <input type="text" width=100><br />
</div> <div style="padding:5px 0px 0px 10px;"> <button type="button">Go</button><br />
</div></div><div style="float:left; width:100px; height:10px;"></div><div style="border:1px solid black; width:250px; height:150px; float:left;"> <div style="padding:5px 0px 0px 20px;" > Screen B<br />
</div> <div style="padding:5px 0px 0px 10px;" > Address: <input type="text" width=100><br />
</div> <div style="padding:5px 0px 0px 12px;"> Location: <input type="text" width=100><br />
</div> <div style="padding:5px 0px 0px 10px;"> <button type="button">Back</button><br />
</div></div><div style="clear:both;"></div><br />
<br><div>Let we need to construct this two screen. Here two screen is very similar, except some text. Let's do it by one layout</div><br><br />
<br />
<br><div style='color:green; font-weight:bold;'>main.xml</div><div style="border:1px solid black"> <font color="#660000" ><pre><?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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/labelA"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Name:"
android:layout_x="0px"
android:layout_y="5px"
/>
<EditText android:id="@+id/edtInput"
android:layout_x="0px"
android:layout_y="40px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
/>
<TextView android:id ="@+id/labelB"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email:"
android:layout_x="0px"
android:layout_y="110px"
/>
<EditText android:id="@+id/edtInputA"
android:layout_x="0px"
android:layout_y="150px"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
/>
<Button android:id ="@+id/btnClick"
android:layout_width="180px"
android:layout_height="70px"
android:text="Open New Screen"
android:textSize="14px"
android:layout_x="0px"
android:layout_y="235px"
/>
</AbsoluteLayout>
</pre></font><br />
</div><br />
<br><div style='color:green; font-weight:bold;'>MultipleScreenSameLayout.java</div><div style="border:1px solid black"> <font color="#660000" ><pre>package com.example.MultipleScreenSameLayout;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MultipleScreenSameLayout 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.btnClick);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// here i call new screen;
Intent i = new Intent(MultipleScreenSameLayout.this,
NewScreen.class);
startActivity(i);
}
});
}
}
</pre></font><br />
</div><br />
<br><div style='color:green; font-weight:bold;'>NewScreen.java</div><div style="border:1px solid black"> <font color="#660000" ><pre>package com.example.MultipleScreenSameLayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class NewScreen extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
<b>
TextView tvB=(TextView) findViewById(R.id.labelB);
tvB.setText("Address:");
TextView tvA=(TextView) findViewById(R.id.labelA);
tvA.setText("Location:");
Button b = (Button) findViewById(R.id.btnClick);
b.setText("Back");
</b>
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
}
</pre></font><br />
</div><br><div><b>Don't fotget add both activity on manifest file</b></div><br><br />
<br />
Output Screen<br><br><br />
Screen A<br />
<div> <img src='http://dl.dropbox.com/u/49962071/blog/android/multi_screen_same_layout_1.JPG' /><br />
</div><br><br />
Screen B<br />
<div style="padding:0px 0px 0px 0px;"> <img src='http://dl.dropbox.com/u/49962071/blog/android/multi_screen_same_layout_2.JPG' /><br />
</div><br>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com1tag:blogger.com,1999:blog-1191825375054982322.post-43146666272355946202011-12-16T10:19:00.000-08:002011-12-16T10:19:56.010-08:00Android multiple screen passing data through intent<div> For passing data one screen to another screen on android you need to pass it through the <b>intent</b>. This example very similar to my <a href="http://start-jandroid.blogspot.com/search/label/Android%20multiple%20screen">previous example</a>, only extra feature is passing data one screen to another screen. Let's go to the example:<br />
</div><br><div style='color:green; font-weight:bold;'>main.xml</div><div style="border:1px solid black"> <font color="#660000" ><pre><?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in the first Screen"
/>
<Button android:id ="@+id/btnClick"
android:layout_width="180px"
android:layout_height="70px"
android:text="Open New Screen"
android:textSize="14px"
/>
</LinearLayout>
</pre></font><br />
</div><br />
<br><div style='color:green; font-weight:bold;'>AndroidMultipleScreenEasy.java</div><div style="border:1px solid black"> <font color="#660000" ><pre>package com.example.AndroidMultipleScreenEasy;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class AndroidMultipleScreenEasy extends Activity {
MyNewScreen obB = new MyNewScreen();
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.btnClick);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
<b>
ArrayList<String> tdata = new ArrayList();
tdata.add("This text from first screen");
// here i call new screen, and pass the data;
Intent i = new Intent(AndroidMultipleScreenEasy.this,
MyNewScreen.class);
i.putExtra("Screen1Data", tdata);
</b>
startActivity(i);
}
});
}
}
</pre></font><br />
</div><br />
<br><div style='color:green; font-weight:bold;'>my_new_screen.xml</div><div style="border:1px solid black"> <font color="#660000" ><pre><?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in the New Screen, press Back for back to previous screen" />
<Button android:id="@+id/btnClick2" android:layout_width="100px"
android:layout_height="50px" android:text="Back" />
<TextView android:id="@+id/myTextViev" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</pre></font><br />
</div><br />
<br />
<br><div style='color:green; font-weight:bold;'>MyNewScreen.java</div><div style="border:1px solid black"> <font color="#660000" ><pre>package com.example.AndroidMultipleScreenEasy;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MyNewScreen extends Activity {
AndroidMultipleScreenEasy ob;
TextView tv;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.my_new_screen);
tv = (TextView) findViewById(R.id.myTextViev);
Intent sender = getIntent();
<b>
ArrayList<String> tdata = (ArrayList) sender.getExtras().getCharSequenceArrayList("Screen1Data");
tv.setText(tdata.get(0));
</b>
Button b = (Button) findViewById(R.id.btnClick2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
}
</pre></font><br />
</div><br><br />
<div><b>Output Screen:</b><br />
</div><br><br />
<div style='float:left; padding-left:10px'> First screen<br><br />
<img src='http://dl.dropbox.com/u/49962071/blog/android/multi_screen_pass_data_1.JPG' /><br />
</div><div style='float:left; padding-left:10px'> Second screen<br><br />
<img src='http://dl.dropbox.com/u/49962071/blog/android/multi_screen_pass_data_2.JPG' /><br />
</div><br>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com1tag:blogger.com,1999:blog-1191825375054982322.post-74357703277323366722011-01-15T00:16:00.000-08:002011-11-17T10:49:31.222-08:00Android multiple screen exampleLet we want constract an application which have two different screen and we want to move one screen to another scrren.</br><br />
</br><br />
At first we need to constract this two screen individually, both screen should <b>extends Activity</b>.<br />
</br>After build two screen you add your new screen to <b>AndroidManifest.xml</b> file (first screen which extends Activity, it's automatically added to <b>AndroidManifest.xml</b>, but all new screen should be added individually).<br />
<br />
</br><br />
<font color="#339900"><b>//main.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="You are in the first Screen"
/>
<Button android:id ="@+id/btnClick"
android:layout_width="150px"
android:layout_height="50px"
android:text="Open New Screen"
/>
</LinearLayout>
</font>
</div></pre><br />
<font color="#339900"><b>//AndroidMultipleScreenEasy.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre>import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
public class AndroidMultipleScreenEasy extends Activity
{
MyNewScreen obB=new MyNewScreen();
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.btnClick);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// here i call new screen;
<b>Intent i = new Intent(AndroidMultipleScreenEasy.this, MyNewScreen.class);
startActivity(i);</b>
}
});
}
}</font></pre></div><br />
<font color="#339900"><b>//my_new_screen.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?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:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="You are in the New Screen, press close for back to previous screen" />
<Button android:id="@+id/btnClick2" android:layout_width="100px"
android:layout_height="50px" android:text="Close" />
</LinearLayout>
</font>
</div></pre><br />
<font color="#339900"><b>//MyNewScreen.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre>import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MyNewScreen extends Activity
{
AndroidMultipleScreenEasy ob;
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.my_new_screen);
Button b = (Button) findViewById(R.id.btnClick2);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
setResult(RESULT_OK);
finish();
}
});
}
public void setOb( AndroidMultipleScreenEasy obA){
this.ob=obA;
}
}</font></pre></div></br><br />
<font color="red"><br />
Add this line to your <b>AndroidManifest.xml</b> file.</br></font><br />
</br><br />
<font color="#339900"><b>//AndroidManifest.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><activity android:name=".MyNewScreen" android:label="MyNewScreenLabel"> </activity>
</font>
</div></pre><br />
<font color="#00000" ><br />
<b>output:<br />
</b><br />
</br><br />
<b>Screen 1</b><br />
</br><br />
Now you can goto new screen by clicking <b>Open New Screen</b> button.<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/jony_android_multiplescreen_easy_screen1.JPG" alt="Image not found"/><br />
</br><br />
<b>Screen 2</b><br />
</br><br />
Now you can goto previous screen by clicking <b>Close</b> button.<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/jony_android_multiplescreen_easy_screen2.JPG" alt="Image not found"/><br />
</font>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com213tag:blogger.com,1999:blog-1191825375054982322.post-66499106758568810392011-01-14T23:10:00.000-08:002011-11-17T10:18:22.452-08:00Android spinner exampleAndroid <b>Spinner</b> help user to select an item from desired items. Here i implements <b>OnItemSelectedListener</b> geting the <b>Spinner</b> selected item. I also set <b>Spinner</b> selected item to a text view (code: <b>selection.setText(items[position]);<br />
</b>). I used <b>LinearLayout</b> here, if you need better positioning you can use AbsoluteLayout. <br />
</br><br />
<font color="#339900"><b>//android_spinner.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?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" />
<Spinner android:id="@+id/spinner" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="true" />
</LinearLayout>
</font>
</div></pre><br />
<font color="#339900"><b>//AndroidSpinner.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre><b>import</b> android.app.Activity;
<b>import</b> android.os.Bundle;
<b>import</b> android.view.View;
<b>import</b> android.widget.AdapterView;
<b>import</b> android.widget.ArrayAdapter;
<b>import</b> android.widget.Spinner;
<b>import</b> android.widget.TextView;
<b>import</b> android.widget.AdapterView.OnItemSelectedListener;
public class AndroidSpinner extends Activity implements <b>OnItemSelectedListener</b> {
TextView selection;
Spinner spin;
String[] items = { "bangladesh", "bangla", "bd", "australia", "japan",
"china", "indiaA", "indiaC" };
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.android_spinner);
selection = (TextView) findViewById(R.id.selection);
Spinner spin = (Spinner) findViewById(R.id.spinner);
spin.setOnItemSelectedListener(this);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, items);
spin.setAdapter(aa);
}
@Override
public void onItemSelected(AdapterView<?> parent, View v, int position,
long id) {
// TODO Auto-generated method stub
<b>selection.setText(items[position]);</b>
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
selection.setText("");
}
}</font></pre></div><font color="#00000" ><br />
<b>output:<br />
</b><br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/jony_android_spinner.JPG" alt="Image not found"/><br />
</font>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com4tag:blogger.com,1999:blog-1191825375054982322.post-5144808400174156282011-01-14T12:56:00.000-08:002011-11-17T10:19:34.827-08:00Android autocompleteAndroid autocompete is very easy. You need to create a <b>AutoCompleteTextView</b>. In AutoCompleteTextView you can set <b>completionThreshold</b> from which character you want to get autocompletion help (here i set 1, means after pressig ist character you will get help for autocomplete).<br />
</br><br />
<font color="#339900"><b>//main.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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" />
<AutoCompleteTextView android:id="@+id/edit"
android:layout_width="150px" android:layout_height="wrap_content"
android:<b>completionThreshold</b>="1" />
<TextView android:id="@+id/myTextViev" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_x="5px"
android:layout_y="110px" />
<Button android:id="@+id/myButton" android:layout_width="100px"
android:layout_height="50px" android:text="Submit" android:layout_x="5px"
android:layout_y="60px" />
</AbsoluteLayout>
</font>
</div></pre><br />
<font color="#339900"><b>//AutoComplete.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre><b>import</b> android.app.Activity;
<b>import</b> android.os.Bundle;
<b>import</b> android.text.Editable;
<b>import</b> android.text.TextWatcher;
<b>import</b> android.view.View;
<b>import</b> android.view.View.OnClickListener;
<b>import</b> android.widget.ArrayAdapter;
<b>import</b> android.widget.AutoCompleteTextView;
<b>import</b> android.widget.Button;
<b>import</b> android.widget.TextView;
public class AutoComplete extends Activity implements TextWatcher,
OnClickListener {
TextView selection;
AutoCompleteTextView edit;
String[] items = { "bangladesh", "india", "pakistan", "australia", "japan",
"china", "indiaA", "indiaC" };
Button btn;
TextView tv;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
selection = (TextView) findViewById(R.id.selection);
edit = (AutoCompleteTextView) findViewById(R.id.edit);
edit.addTextChangedListener(this);
btn = (Button) findViewById(R.id.myButton);
btn.setOnClickListener(this);
tv = (TextView) findViewById(R.id.myTextViev);
edit.setAdapter(new ArrayAdapter<string>(this,
android.R.layout.select_dialog_singlechoice, items));
}
public void onTextChanged(CharSequence s, int start, int before, int count) {
// selection.setText(edit.getText());
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// needed for interface, but not used
}
public void afterTextChanged(Editable s) {
// needed for interface, but not used
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.myButton) {
tv.setText("get: "+edit.getText());
}
}
}</font></pre></div><div><font color="#00000" ><br />
<b>output:<br />
</b><br />
</br><br />
Let you want to type bangladesh or bangla or bd, after pressed <b>b</b> you will get all autocomplete help<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/jony_android_autocomplete_bd.PNG" alt="Image not found"/><br />
</font><br />
</div>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com0tag:blogger.com,1999:blog-1191825375054982322.post-77419427256255563582011-01-14T11:19:00.000-08:002011-11-17T10:20:23.339-08:00Android radion button,Android AbsoluteLayoutFor android radion button you need to create a <b>RadioGroup</b>. From each group<br />
maximum one item can be selected.<br />
Here you also find how get selected radio button.<br />
In this example i used <b>AbsoluteLayout</b> for better positioning.<br />
</br><br />
<font color="#339900"><b>//main.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout 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/myTextViev" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Choose Dictionary:"
android:layout_x="20px" android:layout_y="250px" />
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioButton android:id="@+id/radio1"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Rock" />
<RadioButton android:id="@+id/radio2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Scissors" />
<RadioButton android:id="@+id/radio3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Paper" />
</RadioGroup>
<Button android:id="@+id/myButton" android:layout_width="100px"
android:layout_height="50px" android:text="Submit" android:layout_x="5px"
android:layout_y="60px" />
</AbsoluteLayout>
</font>
</div></pre><br />
<font color="#339900"><b>//AndroidRadioButton.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre>import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.TextView;
public class AndroidRadioButton extends Activity implements OnClickListener{
TextView tv;
Button btn;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn = (Button) findViewById(R.id.myButton);
btn.setOnClickListener(this);
tv = (TextView) findViewById(R.id.myTextViev);
tv.setText("This is sample text");
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
RadioButton ra=(RadioButton)findViewById(R.id.radio1);
RadioButton rb=(RadioButton)findViewById(R.id.radio2);
RadioButton rc=(RadioButton)findViewById(R.id.radio3);
if (v.getId() == R.id.myButton) {
if(ra.isChecked()){
tv.setText("Rock selected");
}
if(rb.isChecked()){
tv.setText("Scissors selected");
}
if(rc.isChecked()){
tv.setText("Paper selected");
}
}
}
}</font></pre></div><div><font color="#00000" ><br />
<b>output:</b></br><br />
select any item of radio button and then click submit button (let i select Scissors radio button),<br />
now output will be<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/android_radio_button.JPG" alt="Image not found"/><br />
</font><br />
</div>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com1tag:blogger.com,1999:blog-1191825375054982322.post-85969506503229275432011-01-14T09:54:00.000-08:002011-11-17T10:22:32.785-08:00Android button/Android button action/AbsoluteLayout/PositioningThis example is very similar to my <a href="http://start-jandroid.blogspot.com/search/label/Android%20button%20action">previous</a> example on button action.</br><br />
Here main difference is <b>positioning</b> your sereen UI component using <b>AbsoluteLayout</b>.<br />
By using android AbsoluteLayout we can easily make positioning.We can positioning using xml or from code.<br />
In this example i showed both.</br><br />
<font color="#339900"><b><br />
//my_button_interface.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?xml version="1.0" encoding="utf-8"?>
<<b>AbsoluteLayout</b> 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/myTextViev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<b>android:layout_x="20px"
android:layout_y="200px"</b>
/>
<Button
android:id="@+id/myButton"
android:layout_width="100px"
android:layout_height="50px"
android:text="Submit"
/>
</<b>AbsoluteLayout</b>>
</font>
</div></pre><br />
<font color="#339900"><b>//HelloWorldAndroid.java</b></font><br />
<div style="border:1px solid black"><font color="#660000" ><br />
<pre><b>import</b> android.app.Activity;
<b>import</b> android.os.Bundle;
<b>import</b> android.view.View;
<b>import</b> android.view.View.OnClickListener;
<b>import</b> android.widget.AbsoluteLayout;
<b>import</b> android.widget.Button;
<b>import</b> android.widget.TextView;
public class AndroidButton extends Activity implements OnClickListener {
/** Called when the activity is first created. */
Button btn;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.my_button_interface);
btn = (Button) findViewById(R.id.myButton);
tv = (TextView) findViewById(R.id.myTextViev);
<b>
AbsoluteLayout.LayoutParams layoutParams= new
AbsoluteLayout.LayoutParams(100,50, 200, 200);
btn.setLayoutParams(layoutParams);
</b>
tv.setText("This is sample text");
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.myButton) {
tv.setText("welcome to AbsoluteLayout");
}
}
}</font></pre></div><div><font color="#00000" ><br />
<b>output:<br />
</b><br />
</br><br />
Before click button<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/android_button_b_1.JPG" alt="Image not found"/><br />
<br />
<br />
After click button<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/android_button_b_2.JPG" alt="Image not found"/><br />
</font><br />
</div>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com0tag:blogger.com,1999:blog-1191825375054982322.post-40696984850213504562011-01-14T04:55:00.000-08:002011-11-17T10:23:40.064-08:00Android button/Android button actionUI design in android is very faster using xml</br><br />
Here i am using <b>linearLayout</b>.</br>From this example we will know how to create a button and then give this button action.Lets see</br><br />
<b>Xml file description:</b><br />
At first i declared here a textview wich will changed after button action performed.<br />
Each elements need a ID, for example textview id is <b>myTextViev</b>. we also define each content layout size and position (<b>AbsoluteLayout</b>).<br />
Then i declared a button (id=myButton,name=Submit) and set button width height</br></br><br />
Now you need to create a file named '<b>my_button_interface.xml</b>' then paste the code below<br />
<font color="#339900"><b><br />
//my_button_interface.xml</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" ><?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/myTextViev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/myButton"
android:layout_width="100px"
android:layout_height="50px"
android:text="Submit"
/>
</LinearLayout>
</font>
</div></pre><br />
<b>Code description:</b></br><br />
First you need to set layout using <b>setContentView(R.layout.my_button_interface)</b>.Now you get all elements of this layout.<br />
If we want to get declare text view code is <b>tv = (TextView) findViewById(R.id.myTextViev)</b>,now you<br />
can set text in this textview.</br>For button action you need to implements OnClickListener,then everything is easy....<br />
<font color="#339900"><b><br />
//AndroidButton.java</b></font><br />
<pre><div style="border:1px solid black"><font color="#660000" >
<b>import</b> android.app.Activity;
<b>import</b> android.os.Bundle;
<b>import</b> android.view.View;
<b>import</b> android.view.View.OnClickListener;
<b>import</b> android.widget.Button;
<b>import</b> android.widget.TextView;
public class <b>AndroidButton</b> extends Activity implements <b>OnClickListener</b> {
<font color="green" >/** Called when the activity is first created. */
</font>
Button btn;
TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.<b>my_button_interface</b>);
btn = (<b>Button</b>) findViewById(R.id.myButton);
tv = (<b>TextView</b>) findViewById(R.id.myTextViev);
tv.setText("This is old text");
btn.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (v.getId() == R.id.<b>myButton</b>) {
tv.setText("This is new text");
}
}
}
</font>
</div></pre><font color="#00000" ><b>output:</b><br />
</br><br />
Before click button<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/android_button_a_1.JPG" alt="Image not found"/><br />
After click button<br />
</br><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/android_button_a_2.JPG" alt="Image not found"/><br />
</font>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com3tag:blogger.com,1999:blog-1191825375054982322.post-56596602523312898462011-01-12T11:44:00.000-08:002011-01-12T11:44:09.633-08:00Installing android<div><b>Installing android:</b><ul> <li>download <a href='http://www.eclipse.org/downloads/'>eclipse</a> ,then extract it.</li>
<li>Install <a href='http://developer.android.com/sdk/eclipse-adt.html'>ADT Plugin</a> from eclips</li>
<li>Install <a href='http://developer.android.com/sdk/installing.html'>Android SDK</a> from eclips</li>
</ul></div>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com0tag:blogger.com,1999:blog-1191825375054982322.post-87734135550005991882011-01-12T11:16:00.000-08:002011-11-17T10:24:48.771-08:00Android Hello World<pre>Android hello world sample code:
Create a android project
Create a class named 'HelloWorldAndroid.java' and then
paste this code
</pre><div style="border:1px solid black"><pre><font color="#339900"><b>
//HelloWorldAndroid.java
</b>
</font>
<font color="#660000" ><b>import</b> android.app.Activity;
<b>import</b> android.os.Bundle;
<b>import</b> android.widget.TextView;
public class HelloWorldAndroid extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
tv.setText("Hello, Android");
setContentView(tv);
}
}
</font>
</pre></div><b>output:<br />
</b><br />
<img src="http://dl.dropbox.com/u/49962071/blog/android/helloworld.JPG" alt="Image not found"/>Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com0tag:blogger.com,1999:blog-1191825375054982322.post-62026928954102737552010-10-31T21:04:00.001-07:002010-10-31T21:04:10.028-07:00First PostI will start posting soon.Abu Zahed Jonyhttp://www.blogger.com/profile/01035226909555729262noreply@blogger.com4