Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Mobile Development > BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2
This is the forum to discuss the Wrox book Professional Android Application Development by Reto Meier; ISBN: 9780470344712
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 23rd, 2009, 01:24 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter-5 on Intents:ContactPickerTester does not show the button "Pick a Contact"

Hi,
I am was trying to run the example from the chapter 5 on Intents... The created the ContactPicker and ContactPckerTester activities. Everything looks ok - compiling, running but I am not sure what to look for. The first activity that gets invoked is "ContactPickerTester" and rightly so , since the manifest defines the intent filter for it as action.MAIN and category.LAUNCHER.

However, it does not do anything after launching activity. I do not see the button to click "Pick Contact" ( the book says "Pick a Contact"). On debug mode , my control gets into a code outside by codebase after it reaches the
button.setOnClickListener(new OnClickListener() ..

Kindly explain to me what is happening?. I have coded both the contactpicker and contactPickerTest and I am convinced that I am passing the correct Intent. However I do not see the what is shown in the figure 5-1.

I am very confused.. thanks a ton for any help..

The full code for the ContactPickerTester.java is:

public
class ContentPickerTester extends Activity {
publicstaticfinalintPICK_CONTACT =1;
/**Calledwhentheactivityisfirstcreated.*/

@Override

publicvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.
contentpickertester);
Button button = (Button)findViewById(R.id.
pick_content_button);
if (button== null)
System.exit(1);
button.setOnClickListener(
new OnClickListener(){
publicvoid onClick(View _view) {
Intent intent =
new Intent(Intent.ACTION_PICK,Uri.parse("content://contacts/"));
startActivityForResult(intent,
PICK_CONTACT);
}
});
}
@Override

protectedvoid onActivityResult(int reqCode, int resCode, Intent data){
//public void OnActivityResult(int reqCode, int resCode, Intent data){

super.onActivityResult(reqCode, resCode, data);
switch(reqCode){
case (PICK_CONTACT):
if (resCode == Activity.RESULT_OK){
Uri ContactData = data.getData();
Cursor c = managedQuery(ContactData,
null, null, null, null);
c.moveToFirst();
String name;
name = c.getString(c.getColumnIndexOrThrow(People.
NAME));
TextView tv ;
tv= (TextView)findViewById(R.id.
selected_contact_textView);
tv.setText(name);
}
break;
}
}
}


The manifest file:
?
xml version="1.0" encoding="utf-8"?>
<
manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.menonmatics.learn.contactpicker"
android:versionCode="1"
android:versionName="1.0.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".ContactPicker"
android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.PICK" />

<category android:name="android.intent.category.DEFAULT" />

<data android:path="contacts"
android:scheme="content">

</data>

</intent-filter>

</activity>

<activity android:name=".ContentPickerTester"
android:label="Contact Picker Test">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>
</application>

<uses-permission android:name="android.permission.READ_CONTACTS"/>

</
manifest>
Reply With Quote
  #2 (permalink)  
Old April 14th, 2009, 02:57 PM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

What about your contactpickertester.xml file? What does that look like?
Reply With Quote
  #3 (permalink)  
Old April 14th, 2009, 03:08 PM
Registered User
 
Join Date: Mar 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default I am attaching the ContactPickerTest.xml file

Hi
Thanks for your response.

attached is my contactpickertest.xml. lemme know what you think: thanks in advance

Code:
<?
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/selected_contact_textView" android:layout_width="fill_parent" android:layout_height="fill_parent" />
<Button android:id="@+id/pick_content_button" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text ="Pick Contact" />
</LinearLayout>

Reply With Quote
  #4 (permalink)  
Old April 15th, 2009, 11:55 AM
Authorized User
 
Join Date: Mar 2009
Posts: 21
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Well, you don't have correct values defined for layout_height of TextView or Button. Instead of "fill_parent", these should be set to "wrap_content".

I'm not exactly sure why a GIANT button isn't created. Maybe Android refuses to create a button that large. But if you correct the XML layout values, you should see the button appear.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code not going as planned: "icicle" vs "savedinstancestate" joopthecat BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 3 May 3rd, 2009 03:09 PM
The Myth of "Good Web Design is in the Graphics" iminore PHP Databases 0 March 9th, 2009 02:02 PM
Message received by "FILE" adapter is suspended skindika Biztalk 0 February 2nd, 2009 07:06 PM
WebPart not supporting/enabled displaymode other than "Browse" amitjoshipune ASP.NET 2.0 Professional 1 January 9th, 2009 02:34 PM
google Response.Write(Request.QueryString("q")) senol01 ASP.NET 2.0 Basics 1 January 2nd, 2009 12:01 PM



All times are GMT -4. The time now is 04:43 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.