[android-beginners] Re: How do I set the value of an EditText

2009-03-28 Thread Tseng

Hehe,
yep, that's the most common error beginers make when start with
android and i already mentioned it in my post above ^^

On Mar 26, 2:41 pm, Lovedumplingx lovedumpli...@gmail.com wrote:
 Holy Mother Dogfood!!!

 I am quite possibly an idiot (that's the second time I'm saying this
 today)!  Wow.  So simple and yet I was looking at it all backward.

 Thanks so much.  It makes sense now.

 On Mar 25, 4:34 pm, Mark Murphy mmur...@commonsware.com wrote:



  Lovedumplingx wrote:
   So I see the NullPointer Exception as a good starting point but I'm
   still perplexed.

   I created a new project just for testing. And I can't get this to
   work:

   package com.test;

   import android.app.Activity;
   import android.os.Bundle;
   import android.widget.EditText;

   public class main extends Activity {
       /** Called when the activity is first created. */
       EditText justFillIn;

     �...@override
       public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);

           justFillIn = (EditText) findViewById(R.id.ipText);
           justFillIn.setText(charSequence is a string);

           setContentView(R.layout.main);
       }
   }

   All I want to do is set the value for that EditText and it's just not
   working.

  You must call setContentView() first.

  You aren't telling Android what layout to display until you call
  setContentView(). Hence, until that time, findViewById() is guaranteed
  not to work, because there are no views to find.

  --
  Mark Murphy (a Commons Guy)http://commonsware.com
  Android App Developer Books:http://commonsware.com/books.html- Hide quoted 
  text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-25 Thread Lovedumplingx

So I see the NullPointer Exception as a good starting point but I'm
still perplexed.

I created a new project just for testing. And I can't get this to
work:

package com.test;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class main extends Activity {
/** Called when the activity is first created. */
EditText justFillIn;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

justFillIn = (EditText) findViewById(R.id.ipText);
justFillIn.setText(charSequence is a string);

setContentView(R.layout.main);
}
}

All I want to do is set the value for that EditText and it's just not
working.

Any help?

On Mar 23, 10:55 am, Lovedumplingx lovedumpli...@gmail.com wrote:
 I get a NullPointer Exception when I use the Debug tool.

 So you're saying that I haven't successfully read the View probably?
 Ok...that's a great starting point.

 On Mar 21, 5:55 am, Tseng tseng.priv...@googlemail.com wrote:

  An error message would be helpful Otherwise it's hard to help you,
  other than guessing what could be the reasons for it.

  Maybe you haven't set the ID correctly, using a wrong ID (which
  doesn't even exist in the XML Layout file) or you're using
  setContentView/setView after you have using findViewById. This could
  throw up a NullPointer Exception when you try to access (because
  findViewById returns 0 if no layout has been set or the View with this
  ID was not found).

  On Mar 20, 9:00 pm, Lovedumplingx lovedumpli...@gmail.com wrote:

   That's what I thought too but I crash the task every time the activity
   that contains this code is started:

  EditTextuserText = (EditText) findViewById(R.id.userText);
   userText.setText(userParam);

   This is the basic way I thought to have the value set but it crashes
   every time.

   On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote:

A String _is_ a CharSequence. There is no need for a cast.

On Mar 19, 3:35 pm, Will sem...@gmail.com wrote:

 Cast the String to a CharSequence.

 String x = foo;
EditTextET;
 ET.setText((CharSequence) x);

 On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:

  Ok...so I've scoured and scoured and played and fiddled but I can't
  figure it out.

  I want to allow the user to set preferences for an application and I
  want the preferences to be displayed in theEditTextarea if/when they
  come back to change them again.

  In my head I'm thinking I would be able to use setText() but 
  no...that
  takes a CharSequence and I have a string and don't know how to make 
  a
  CharSequence (which according to what I've read is supposed to be a
  read-only thing anyway).

  So...does anyone know how to put text into anEditTextfield without
  relying on the XML?  I really want to do this via application
  preferences.

  Thanks.- Hide quoted text -

   - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-25 Thread Mark Murphy

Lovedumplingx wrote:
 So I see the NullPointer Exception as a good starting point but I'm
 still perplexed.
 
 I created a new project just for testing. And I can't get this to
 work:
 
 package com.test;
 
 import android.app.Activity;
 import android.os.Bundle;
 import android.widget.EditText;
 
 public class main extends Activity {
 /** Called when the activity is first created. */
 EditText justFillIn;
 
   @Override
 public void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 
 justFillIn = (EditText) findViewById(R.id.ipText);
 justFillIn.setText(charSequence is a string);
 
 setContentView(R.layout.main);
 }
 }
 
 All I want to do is set the value for that EditText and it's just not
 working.

You must call setContentView() first.

You aren't telling Android what layout to display until you call
setContentView(). Hence, until that time, findViewById() is guaranteed
not to work, because there are no views to find.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-23 Thread Lovedumplingx

I get a NullPointer Exception when I use the Debug tool.

So you're saying that I haven't successfully read the View probably?
Ok...that's a great starting point.

On Mar 21, 5:55 am, Tseng tseng.priv...@googlemail.com wrote:
 An error message would be helpful Otherwise it's hard to help you,
 other than guessing what could be the reasons for it.

 Maybe you haven't set the ID correctly, using a wrong ID (which
 doesn't even exist in the XML Layout file) or you're using
 setContentView/setView after you have using findViewById. This could
 throw up a NullPointer Exception when you try to access (because
 findViewById returns 0 if no layout has been set or the View with this
 ID was not found).

 On Mar 20, 9:00 pm, Lovedumplingx lovedumpli...@gmail.com wrote:

  That's what I thought too but I crash the task every time the activity
  that contains this code is started:

 EditTextuserText = (EditText) findViewById(R.id.userText);
  userText.setText(userParam);

  This is the basic way I thought to have the value set but it crashes
  every time.

  On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote:

   A String _is_ a CharSequence. There is no need for a cast.

   On Mar 19, 3:35 pm, Will sem...@gmail.com wrote:

Cast the String to a CharSequence.

String x = foo;
   EditTextET;
ET.setText((CharSequence) x);

On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:

 Ok...so I've scoured and scoured and played and fiddled but I can't
 figure it out.

 I want to allow the user to set preferences for an application and I
 want the preferences to be displayed in theEditTextarea if/when they
 come back to change them again.

 In my head I'm thinking I would be able to use setText() but no...that
 takes a CharSequence and I have a string and don't know how to make a
 CharSequence (which according to what I've read is supposed to be a
 read-only thing anyway).

 So...does anyone know how to put text into anEditTextfield without
 relying on the XML?  I really want to do this via application
 preferences.

 Thanks.- Hide quoted text -

  - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-21 Thread Tseng

An error message would be helpful Otherwise it's hard to help you,
other than guessing what could be the reasons for it.

Maybe you haven't set the ID correctly, using a wrong ID (which
doesn't even exist in the XML Layout file) or you're using
setContentView/setView after you have using findViewById. This could
throw up a NullPointer Exception when you try to access (because
findViewById returns 0 if no layout has been set or the View with this
ID was not found).


On Mar 20, 9:00 pm, Lovedumplingx lovedumpli...@gmail.com wrote:
 That's what I thought too but I crash the task every time the activity
 that contains this code is started:

 EditText userText = (EditText) findViewById(R.id.userText);
 userText.setText(userParam);

 This is the basic way I thought to have the value set but it crashes
 every time.

 On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote:



  A String _is_ a CharSequence. There is no need for a cast.

  On Mar 19, 3:35 pm, Will sem...@gmail.com wrote:

   Cast the String to a CharSequence.

   String x = foo;
  EditTextET;
   ET.setText((CharSequence) x);

   On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:

Ok...so I've scoured and scoured and played and fiddled but I can't
figure it out.

I want to allow the user to set preferences for an application and I
want the preferences to be displayed in theEditTextarea if/when they
come back to change them again.

In my head I'm thinking I would be able to use setText() but no...that
takes a CharSequence and I have a string and don't know how to make a
CharSequence (which according to what I've read is supposed to be a
read-only thing anyway).

So...does anyone know how to put text into anEditTextfield without
relying on the XML?  I really want to do this via application
preferences.

Thanks.- Hide quoted text -

 - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-21 Thread sm1

i use

  myEditText.setText(hello, TextView.BufferType.EDITABLE);

works fine
serge

On Mar 21, 5:55 am, Tseng tseng.priv...@googlemail.com wrote:
 An error message would be helpful Otherwise it's hard to help you,
 other than guessing what could be the reasons for it.

 Maybe you haven't set the ID correctly, using a wrong ID (which
 doesn't even exist in the XML Layout file) or you're using
 setContentView/setView after you have using findViewById. This could
 throw up a NullPointer Exception when you try to access (because
 findViewById returns 0 if no layout has been set or the View with this
 ID was not found).

 On Mar 20, 9:00 pm, Lovedumplingx lovedumpli...@gmail.com wrote:

  That's what I thought too but I crash the task every time the activity
  that contains this code is started:

  EditText userText = (EditText) findViewById(R.id.userText);
  userText.setText(userParam);

  This is the basic way I thought to have the value set but it crashes
  every time.

  On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote:

   A String _is_ a CharSequence. There is no need for a cast.

   On Mar 19, 3:35 pm, Will sem...@gmail.com wrote:

Cast the String to a CharSequence.

String x = foo;
   EditTextET;
ET.setText((CharSequence) x);

On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:

 Ok...so I've scoured and scoured and played and fiddled but I can't
 figure it out.

 I want to allow the user to set preferences for an application and I
 want the preferences to be displayed in theEditTextarea if/when they
 come back to change them again.

 In my head I'm thinking I would be able to use setText() but no...that
 takes a CharSequence and I have a string and don't know how to make a
 CharSequence (which according to what I've read is supposed to be a
 read-only thing anyway).

 So...does anyone know how to put text into anEditTextfield without
 relying on the XML?  I really want to do this via application
 preferences.

 Thanks.- Hide quoted text -

  - Show quoted text -
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-20 Thread Lovedumplingx

That's what I thought too but I crash the task every time the activity
that contains this code is started:

EditText userText = (EditText) findViewById(R.id.userText);
userText.setText(userParam);

This is the basic way I thought to have the value set but it crashes
every time.

On Mar 19, 10:53 pm, Isaac Waller ad...@isaacwaller.com wrote:
 A String _is_ a CharSequence. There is no need for a cast.

 On Mar 19, 3:35 pm, Will sem...@gmail.com wrote:

  Cast the String to a CharSequence.

  String x = foo;
 EditTextET;
  ET.setText((CharSequence) x);

  On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:

   Ok...so I've scoured and scoured and played and fiddled but I can't
   figure it out.

   I want to allow the user to set preferences for an application and I
   want the preferences to be displayed in theEditTextarea if/when they
   come back to change them again.

   In my head I'm thinking I would be able to use setText() but no...that
   takes a CharSequence and I have a string and don't know how to make a
   CharSequence (which according to what I've read is supposed to be a
   read-only thing anyway).

   So...does anyone know how to put text into anEditTextfield without
   relying on the XML?  I really want to do this via application
   preferences.

   Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---



[android-beginners] Re: How do I set the value of an EditText

2009-03-19 Thread Will

Cast the String to a CharSequence.

String x = foo;
EditText ET;
ET.setText((CharSequence) x);


On Mar 19, 10:43 am, Lovedumplingx lovedumpli...@gmail.com wrote:
 Ok...so I've scoured and scoured and played and fiddled but I can't
 figure it out.

 I want to allow the user to set preferences for an application and I
 want the preferences to be displayed in the EditText area if/when they
 come back to change them again.

 In my head I'm thinking I would be able to use setText() but no...that
 takes a CharSequence and I have a string and don't know how to make a
 CharSequence (which according to what I've read is supposed to be a
 read-only thing anyway).

 So...does anyone know how to put text into an EditText field without
 relying on the XML?  I really want to do this via application
 preferences.

 Thanks.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
Groups Android Beginners group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~--~~~~--~~--~--~---