p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Professional Android Application Development ISBN: 978-0-470-34471-2 (http://p2p.wrox.com/forumdisplay.php?f=432)
-   -   Chapter-5 on Intents:ContactPickerTester does not show the button "Pick a Contact" (http://p2p.wrox.com/showthread.php?t=73513)

sunilm12 March 23rd, 2009 01:24 PM

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..[:confused:]

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>

sierawsk April 14th, 2009 02:57 PM

What about your contactpickertester.xml file? What does that look like?

sunilm12 April 14th, 2009 03:08 PM

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>



sierawsk April 15th, 2009 11:55 AM

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.


All times are GMT -4. The time now is 03:57 PM.

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