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. Virtual KeyPad for Android on OMAP Processor

Hello,

I've deployed Android on Omap Processor Board.
I've also created some android application which requires user
interface (Alpha -Numeric ) input from User.
Can anybody help me to invoke the android Virtual Keypad on OMAP
Processor ?

Your reply will be highly appreciated.

Thanks & Regards,
Rakesh Bohra

-- 

2. Monkey tool: Launch a particular Activity

I want to launch only a single Activity in a package using Monkey and
allow it to perform the random event testing. The only option I see to
use -c with CATEGORY_MONKEY and modify my activity in the
AndroidManifest to add this category to my activity?  Though when I
tried with an activity with android.intent.category.DEFAULT, it exited
without running any tests.

Any idea if this is supported - launching only a single Activity with
monkey?

-- 

3. seeking information to get started

4. User Space Hardware Abstraction Layer Development Guide

5. broken touch screen

6. creating default.properties when making a project using IntelliJ Idea

7. keytool error - unknown format