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. SYSFS based accelorometer

yet another random question here, currently i have a accelorometer in
my device (nokia N900 - acceloropmeter is a LIS302DL) that exports its
data to a sysfs location (/sys/class/i2c-adapter/i2c-3/3-001d) not an
input event (the newer kernels have a input device but those kernels
will not compile for my device) so does anyone have any clue how i can
persuade android to use the accelormeters details without an input or
how i can hack the driver to give me a event device

-- 
unsubscribe: android-porting+unsubscr...@googlegroups.com
website: 

2. Getting and Sending Data From the Web (URLConnection via http)

Hi Guys,
I wanted to create a an android application that works like a remote
control for a multimedia system. This client server dialog is done on
the json class api. The class that I use for establishing the
communication is the HttpURLConnection. I used the following example
for writing my programm( 
http://www.anddev.org/getting_data_from_the_web_urlconnection_via_http-t351.html
).
I ran wireshark to monitor the communication, and i see the data that
is being sent from the server, but sending orders back to the server
from my milestone doesn't happen at all.
I turned off all my firewalls that could interfere with the
communication.

-- 

3. How Truncate Text With 3dots In Table Layout

4. Icon issue - building with 2.1 sdk for 1.5 target

5. Animation in List, When contents are more

6. Could not upload a new application

7. NEED help--working on twitter app want list click to be expanded and again shrinked on another click plz help