Problem with textview in a Dialog

by Chavepeyer Geoffrey » Tue, 10 Mar 2009 00:45:10 GMT


Sponsored Links
 Hi everyone :)

I'm a real beginner in Android and find it really coll but I do have
one problem :

This is what I'm trying to do : set the dialog content view whos
description is in a XML file and change the value of some of those
textfield. Like this :

Dialog d = new Dialog(context);
d.setTitle(R.string.MeetingDetails);
d.setContentView(R.layout.meeting_detail);

TextView tv = (TextView) findViewById(R.id.MDDateVALUE);
tv.setText("TEST");

d.show();

and my meetind_detail.xml file :

<?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="wrap_content"
android:layout_height="wrap_content" android:id="@+id/MDDate"
android:text="@string/MeetingDetailsDate"></TextView>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/MDDateVALUE" ></
TextView>
</LinearLayout>


But when calling the setText(...) method on the "tv" object I got a
NullPointerException because tv is null.
I guess the view is not loaded yet and therefore the textfield doesnt
exists yet.

What am I supposed to do ?

Thanks a lot everyone for your help :)

Geoffrey.

--~--~---------~--~----~------------~-------~--~----~



Problem with textview in a Dialog

by Chavepeyer Geoffrey » Tue, 10 Mar 2009 18:30:31 GMT


 So, I've created a test case but still encounter the same problem:

package be.geoc.DialogTest;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class Dialog_Test 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.Button01);

        b.setOnClickListener(new View.OnClickListener(){

                        public void onClick(View arg0) {
                                Dialog d = new Dialog(Dialog_Test.this);
                        d.setContentView(R.layout.meeting_detail);


                        TextView tv = (TextView) findViewById(R.id.TextView01);
                        System.out.println(tv);
                        tv.setText("TEST");

                        d.show();

                        }

        });
    }
}

And the 2 xml layout files :
main.xml :

<?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="@string/hello" android:id="@+id/TextView"/>
<Button android:id="@+id/Button01" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:text="Ouvrir le dialog"></
Button>
</LinearLayout>


and meeting_detail.xml :

<?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/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</LinearLayout>


Is anyone able to help me ?
Thanks a lot !!!

Geoffrey
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


Problem with textview in a Dialog

by Chavepeyer Geoffrey » Wed, 11 Mar 2009 16:09:57 GMT


 Nobody to help me ?



On Mar 10, 11:30am, Chavepeyer Geoffrey <gchavepe...@gmail.com>


--~--~---------~--~----~------------~-------~--~----~



Problem with textview in a Dialog

by Chavepeyer Geoffrey » Thu, 12 Mar 2009 18:52:15 GMT


 ound the problem :
I needed to call the findViewById() method on the dialog like this :

TextView tv = (TextView) d.findViewById(R.id.TextView01);

and not like this :

TextView tv = (TextView) findViewById(R.id.TextView01);

Geoffrey.

On 11 mar, 09:09, Chavepeyer Geoffrey <gchavepe...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. possible network issue on Android 2.0

Some  Droid phones drop internet connection
When customer sent log i see several onCellLocationChanged
He tells me he never moved more than few feet during that time and it
only happens on 3G not over wifi
Is it possible Droid dropping persistent network connection because
the phone changes cell towers?
Why would the phone change cell towers from same location
There is no problem with any G1 or Hero phones only Droid
Thanks

-- 

2. Android Telephony

Hi

I want to find the network signal strength for my app.
But I cant find the api for it.

Do anybody know how to find the signal strength of the phone?

Thanks
--~--~---------~--~----~------------~-------~--~----~

3. Infinite Reboot Cycle Caused by Choosing a Remote Location Picture as a Background

4. AudioTrack usage with streaming data in native code

5. Send numbers during call

6. Not able to write to /storage

7. onNewIntent() is never called when use Icons