Ch04 Listings
satya - Friday, February 26, 2010 8:11:44 PM
Listing 4-1
package pro.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity
{
private LinearLayout nameContainer;
private LinearLayout addressContainer;
private LinearLayout parentContainer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
createNameContainer();
createAddressContainer();
createParentContainer();
setContentView(parentContainer);
}
private void createNameContainer()
{
nameContainer = new LinearLayout(this);
nameContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
nameContainer.setOrientation(LinearLayout.HORIZONTAL);
TextView nameLbl = new TextView(this);
nameLbl.setText("Name: ");
nameContainer.addView(nameLbl);
TextView nameValueLbl = new TextView(this);
nameValueLbl.setText("John Doe");
nameContainer.addView(nameValueLbl);
}
private void createAddressContainer()
{
addressContainer = new LinearLayout(this);
addressContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
addressContainer.setOrientation(LinearLayout.VERTICAL);
TextView addrLbl = new TextView(this);
addrLbl.setText("Address:");
TextView addrValueLbl = new TextView(this);
addrValueLbl.setText("911 Hollywood Blvd");
addressContainer.addView(addrLbl);
addressContainer.addView(addrValueLbl);
}
private void createParentContainer()
{
parentContainer = new LinearLayout(this);
parentContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
parentContainer.setOrientation(LinearLayout.VERTICAL);
parentContainer.addView(nameContainer);
parentContainer.addView(addressContainer);
}
}
package pro.android;
import android.app.Activity;
import android.os.Bundle;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class MainActivity extends Activity
{
private LinearLayout nameContainer;
private LinearLayout addressContainer;
private LinearLayout parentContainer;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
createNameContainer();
createAddressContainer();
createParentContainer();
setContentView(parentContainer);
}
private void createNameContainer()
{
nameContainer = new LinearLayout(this);
nameContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
nameContainer.setOrientation(LinearLayout.HORIZONTAL);
TextView nameLbl = new TextView(this);
nameLbl.setText("Name: ");
nameContainer.addView(nameLbl);
TextView nameValueLbl = new TextView(this);
nameValueLbl.setText("John Doe");
nameContainer.addView(nameValueLbl);
}
private void createAddressContainer()
{
addressContainer = new LinearLayout(this);
addressContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
addressContainer.setOrientation(LinearLayout.VERTICAL);
TextView addrLbl = new TextView(this);
addrLbl.setText("Address:");
TextView addrValueLbl = new TextView(this);
addrValueLbl.setText("911 Hollywood Blvd");
addressContainer.addView(addrLbl);
addressContainer.addView(addrValueLbl);
}
private void createParentContainer()
{
parentContainer = new LinearLayout(this);
parentContainer.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
parentContainer.setOrientation(LinearLayout.VERTICAL);
parentContainer.addView(nameContainer);
parentContainer.addView(addressContainer);
}
}
satya - Friday, February 26, 2010 8:12:42 PM
Listing 4-2
<?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">
<!-- NAME CONTAINER -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Name:" />
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="John Doe" />
</LinearLayout>
<!-- ADDRESS CONTAINER -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="Address:" />
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="911 Hollywood Blvd." />
</LinearLayout>
</LinearLayout>
satya - Friday, February 26, 2010 8:13:43 PM
Listing 4-3
<?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">
<!-- NAME CONTAINER -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/nameText" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="@+string/name_text" />
<TextView android:id="@+id/nameValueText"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<!-- ADDRESS CONTAINER -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/addrText" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@+string/addr_text" />
<TextView android:id="@+id/addrValueText"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
satya - Friday, February 26, 2010 8:14:20 PM
Listing 4-4
setContentView(R.layout.main);
TextView nameValue = (TextView)findViewById(R.id.nameValueText);
nameValue.setText("John Doe");
TextView addrValue = (TextView)findViewById(R.id.addrValueText);
addrValue.setText("911 Hollywood Blvd.");
satya - Friday, February 26, 2010 8:14:42 PM
Listing 4-5
TextView tv =(TextView)this.findViewById(R.id.cctvex);
tv.setText("Please visit my website, http://www.sayedhashimi.com
or email me at sayed@sayedhashimi.com.");
Linkify.addLinks(tv, Linkify.ALL);
satya - Friday, February 26, 2010 8:15:30 PM
Listing 4-6
EditText et =(EditText)this.findViewById(R.id.cctvex5);
et.setText("Styling the content of an editText dynamically");
Spannable spn = et.getText();
spn.setSpan(new BackgroundColorSpan(Color.RED), 0, 7,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spn.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC)
, 0, 7, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
satya - Friday, February 26, 2010 8:16:26 PM
Listing 4-7
AutoCompleteTextView actv = (AutoCompleteTextView) this.findViewById(R.id.ccactv);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,
new String[] {"English", "Hebrew", "Hindi", "Spanish", "German", "Greek" });
actv.setAdapter(aa);
satya - Friday, February 26, 2010 8:16:53 PM
Listing 4-8
MultiAutoCompleteTextView mactv = (MultiAutoCompleteTextView) this
.findViewById(R.id.ccmactv);
ArrayAdapter<String> aa2 = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line,
new String[] {"English", "Hebrew", "Hindi", "Spanish", "German", "Greek" });
mactv.setAdapter(aa2);
mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
satya - Friday, February 26, 2010 8:17:24 PM
Listing 4-9
Button btn = (Button)this.findViewById(R.id.ccbtn1);
btn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
Intent intent = getButtonIntent();
intent.setAction("some intent data");
setResult(RESULT_OK, intent);
finish();
}
});
satya - Friday, February 26, 2010 8:17:55 PM
Listing 4-9 xml
<Button android:id="@+id/ccbtn1"
android:text="@+string/basicBtnLabel"
android:typeface="serif" android:textStyle="bold"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
satya - Friday, February 26, 2010 8:18:15 PM
Listing 4-10
ImageButton btn = (ImageButton)this.findViewById(R.id.imageBtn);
btn.setImageResource(R.drawable.icon);
satya - Friday, February 26, 2010 8:18:35 PM
Listing 4-10 xml
<ImageButton android:id="@+id/imageBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
satya - Friday, February 26, 2010 8:19:09 PM
Listing 4-11
<ImageButton android:id="@+id/imageBtn"
android:src="@drawable/btnImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
satya - Friday, February 26, 2010 8:19:43 PM
Listing 4-12
<ToggleButton android:id="@+id/cctglBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toggle Button"/>
satya - Friday, February 26, 2010 8:20:06 PM
Listing 4-13
<ToggleButton android:id="@+id/cctglBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Run"
android:textOff="Stop"
android:text="Toggle Button"/>
satya - Friday, February 26, 2010 8:20:30 PM
Listing 4-14
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<CheckBox android:text="Chicken"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<CheckBox android:text="Fish"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<CheckBox android:text="Steak"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
satya - Friday, February 26, 2010 8:21:06 PM
Listing 4-15
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioGroup android:id="@+id/rBtnGrp" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RadioButton android:id=�?�@+id/chRBtn�?� android:text="Chicken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id=�?�@+id/fishRBtn�?� android:text="Fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id=�?�@+id/stkRBtn�?� android:text="Steak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
satya - Friday, February 26, 2010 8:21:32 PM
Listing 4-16
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RadioButton android:id="@+id/anotherRadBtn"
android:text="Outside"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioGroup android:id="@+id/rdGrp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton android:id="@+id/chRBtn"
android:text="Chicken"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/fishRBtn"
android:text="Fish"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<RadioButton android:id="@+id/stkRBtn"
android:text="Steak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView android:text="My Favorite"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RadioGroup>
</LinearLayout>
satya - Friday, February 26, 2010 8:22:02 PM
Listing 4-17
public class ListDemoActivity extends ListActivity
{
private SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
String[] cols = new String[]{People.NAME};
int[] names = new int[]{R.id.row_tv};
adapter = new SimpleCursorAdapter(this,R.layout.list_item,c,cols,names);
this.setListAdapter(adapter);
}
}
satya - Friday, February 26, 2010 8:22:41 PM
Listing 4-17 xml
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/list_item.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<CheckBox xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/row_chbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView android:id="@+id/row_tv" android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
satya - Friday, February 26, 2010 8:23:00 PM
Listing 4-18
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/list.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:stackFromBottom="true"
android:transcriptMode="normal"/>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Submit Selection" />
</LinearLayout>
satya - Friday, February 26, 2010 8:23:17 PM
Listing 4-19
public class ListDemoActivity extends ListActivity
{
private SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
String[] cols = new String[]{People.NAME};
int[] names = new int[]{R.id.row_tv};
adapter = new SimpleCursorAdapter(this,R.layout.list_item,c,cols,names);
this.setListAdapter(adapter);
}
}
satya - Friday, February 26, 2010 8:24:04 PM
Listing 4-20
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
GridView gv = (GridView)this.findViewById(R.id.dataGrid);
Cursor c = getContentResolver().query(People.CONTENT_URI,
null, null, null, null);
startManagingCursor(c);
String[] cols = new String[]{People.NAME};
int[] names = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1 ,c,cols,names);
gv.setAdapter(adapter);
}
satya - Friday, February 26, 2010 8:24:59 PM
Listing 4-20 xml
<?xml version="1.0" encoding="utf-8"?>
<!-- This file is at /res/layout/gridview.xml -->
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dataGrid"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px"
android:verticalSpacing="10px"
android:horizontalSpacing="10px"
android:numColumns="auto_fit"
android:columnWidth="100px"
android:stretchMode="columnWidth"
android:gravity="center"
/>
satya - Friday, February 26, 2010 8:25:20 PM
Listing 4-21
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<DatePicker android:id="@+id/datePicker"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<TimePicker android:id="@+id/timePicker"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>
satya - Friday, February 26, 2010 8:26:59 PM
Listing 4-22
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.datetime);
DatePicker dp = (DatePicker)this.findViewById(R.id.datePicker);
dp.init(2008, 11, 10, null);
TimePicker tp = (TimePicker)this.findViewById(R.id.timePicker);
tp.setIs24HourView(true);
tp.setCurrentHour(new Integer(10));
tp.setCurrentMinute(new Integer(10));
}
satya - Friday, February 26, 2010 8:28:22 PM
Listing 4-23
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.google.android.maps.MapView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:enabled="true"
android:clickable="true"
android:apiKey="myAPIKey"
/>
</LinearLayout>
satya - Friday, February 26, 2010 8:28:45 PM
Listing 4-24
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<!-- add children here-->
</LinearLayout>
satya - Friday, February 26, 2010 8:30:10 PM
Listing 4-25
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="one"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="two"/>
<EditText android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="three"/>
</LinearLayout>
satya - Friday, February 26, 2010 8:32:16 PM
Listing 4-26
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_width="fill_parent" android:layout_weight="0.0"
android:layout_height="wrap_content" android:text="one"
android:gravity="left"/>
<EditText android:layout_width="fill_parent" android:layout_weight="1.0"
android:layout_height="wrap_content" android:text="two"
android:gravity="center"/>
<EditText android:layout_width="fill_parent" android:layout_weight="0.0"
android:layout_height="wrap_content" android:text="three"
android:gravity="right"
/>
</LinearLayout>
satya - Friday, February 26, 2010 8:32:38 PM
Listing 4-27
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_width="wrap_content" android:gravity="center"
android:layout_height="wrap_content" android:text="one"
android:layout_gravity="right"/>
</LinearLayout>
satya - Friday, February 26, 2010 8:33:16 PM
Listing 4-28
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="First Name:"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Barack"/>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Last Name:"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Obama"/>
</TableRow>
</TableLayout>
satya - Friday, February 26, 2010 8:33:39 PM
Listing 4-29
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="First Name:"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Barack"/>
</TableRow>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Last Name:"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Hussein"/>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Obama"/>
</TableRow>
</TableLayout>
satya - Friday, February 26, 2010 8:34:03 PM
Listing 4-30
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:stretchColumns="0,1,2">
<EditText
android:text="Full Name:"/>
<TableRow>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Barack"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Hussein"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Obama"/>
</TableRow>
</TableLayout>
satya - Friday, February 26, 2010 8:34:36 PM
Listing 4-31
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="one"
android:padding="40px" />
</LinearLayout>
satya - Friday, February 26, 2010 8:34:56 PM
Listing 4-32
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:id="@+id/userNameLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Username: "
android:layout_alignParentTop="true" />
<EditText android:id="@+id/userNameText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNameLbl" />
<TextView android:id="@+id/pwdLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/userNameText"
android:text="Password: " />
<EditText android:id="@+id/pwdText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pwdLbl" />
<TextView android:id="@+id/pwdHintLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/pwdText"
android:text="Password Criteria... " />
<TextView android:id="@+id/disclaimerLbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:text="Use at your own risk... " />
</RelativeLayout>
satya - Friday, February 26, 2010 8:35:42 PM
Listing 4-33
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.frame);
ImageView one = (ImageView)this.findViewById(R.id.oneImgView);
ImageView two = (ImageView)this.findViewById(R.id.twoImgView);
one.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view) {
ImageView two = (ImageView)FramelayoutActivity.this.
findViewById(R.id.twoImgView);
two.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
}});
two.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View view) {
ImageView one = (ImageView)FramelayoutActivity.
this.findViewById(R.id.oneImgView);
one.setVisibility(View.VISIBLE);
view.setVisibility(View.GONE);
}});
}
satya - Friday, February 26, 2010 8:39:24 PM
Listing 4-33 xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/frmLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/oneImgView" android:src="@drawable/one"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<ImageView
android:id="@+id/twoImgView" android:src="@drawable/two"
android:scaleType="fitCenter"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone" />
</FrameLayout>
satya - Friday, February 26, 2010 8:39:49 PM
Listing 4-34
Spinner s2 = (Spinner) findViewById(R.id.spinner2);
adapter = ArrayAdapter.createFromResource(this,
R.array.planets,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s2.setAdapter(adapter);
<string-array name="planets">
<item>Mercury</item>
<item>Venus</item>
<item>Earth</item>
<item>Mars</item>
<item>Jupiter</item>
<item>Saturn</item>
<item>Uranus</item>
<item>Neptune</item>
</string-array>