How do I set the value of an EditText

by Lovedumplingx » Thu, 19 Mar 2009 22:43:35 GMT


Sponsored Links
 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.
--~--~---------~--~----~------------~-------~--~----~



How do I set the value of an EditText

by Will » Fri, 20 Mar 2009 06:35:41 GMT


 Cast the String to a CharSequence.

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




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


Sponsored Links


How do I set the value of an EditText

by Isaac Waller » Fri, 20 Mar 2009 12:28:20 GMT


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





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



How do I set the value of an EditText

by Lovedumplingx » Sat, 21 Mar 2009 04:00:59 GMT


 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.





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



How do I set the value of an EditText

by Tseng » Sat, 21 Mar 2009 17:57:05 GMT


 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).







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



How do I set the value of an EditText

by sm1 » Sun, 22 Mar 2009 00:28:11 GMT


 i use

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

works fine
serge







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



How do I set the value of an EditText

by Lovedumplingx » Mon, 23 Mar 2009 22:55:06 GMT


 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.







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



How do I set the value of an EditText

by Lovedumplingx » Thu, 26 Mar 2009 04:22:21 GMT


 o 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:55am, Lovedumplingx <lovedumpli...@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



How do I set the value of an EditText

by Mark Murphy » Thu, 26 Mar 2009 04:34:27 GMT


 


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 

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



How do I set the value of an EditText

by Lovedumplingx » Thu, 26 Mar 2009 21:41:27 GMT


 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.





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



How do I set the value of an EditText

by Tseng » Sun, 29 Mar 2009 00:39:41 GMT


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





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



Other Threads

1. How do I save the scroll position of a WebView?

Hello,

I wonder how I can save the scroll position in a WebView in
SharedPreferences for example. I wonder how I can save the scroll
position in a WebView in SharedPreferences for example (but not if it
is more appropriate in the Bundle) and then restore when the Activity
is reapear.


Bye!

2. Reducing Boot time

Hi,

Our processor is PXA255 and its take long time to boot Android. It takes
almost 8mins :(.

I downloaded the source and compiled it for default "generic" product.

1. Can anyone let me know, how to diable Internet (libwebcore) as we do not
want that stuff?
2. I included "disabled" in the init.rc file for service "media", but still
mediaserver is running in the background. which is not needed us.

Please let me know, if there is any documentation available.

Thanks

3. Problems Compiling Sudoku sample program

4. mkdir

5. Decad锚ncia de um jornalista que ja foi ancora de telejornais com grande audi锚ncia...

6. Why differs the size of my app in the market to the real size of my app on my computer? How can I make the market-version smaller?

7. Displaying multiple locations on a mapview