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. Button placement problems

Hello,

I could find anything similar so I decided to open a new thread.
However if there already is a similar answer please post the link.

I need to place my buttons in a little unconventional way shown here
(dkw I could post the message with an imageshack link so an ASCI
'picture'):

___________________
|                                |
|                                |
|                                |
|                                |
|                                |
|                                |
|__________________|
|_______B1_________|
|                                |
|________   ________ |
|___B2___|_|___ B3__ |

In fact I need it working in a second screen without B2.

So far my code is the following:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/layout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="@drawable/id_app2" android:orientation="vertical"
android:gravity="fill">

<Button android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_gravity="center_vertical"
android:layout_marginTop="291dp"
android:layout_height="40dp">
</Button>

<Button android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:height="30dp"
android:width="160dp"
 android:layout_gravity="bottom|right"
android:layout_marginTop="70dp">
</Button>
</LinearLayout>

(for simplicity I have removed the B2 from the code) An it worked on
my Samsung Galaxy. However I tried the same app on my friends acer
phone and the buttons were higher that should be. This is a little bit
strange since everything on other screens works fine (as you can see I
use dp not px) - I only have problem with this one. How to place them
so they would be the same at every device?

PS: For clarity B1 is a  below the center of the screen.

-- 

2. Streaming mp3 file with RTSP protocol

hi all,
I am trying play a mp3 stream file using rtsp protocol. To do this i
am using the DarwinStreamingSrvr as a RTSP server and mediaplayer to
play the RTSP link.
I already tried play the mp4 video file and i didn't had any problems.
However, when i try play the mp3 file i don't have sucess and i get
the error:


V/AudioStreamPlayer(10476): playRTSPAudioURL :: IN
I/QC_CORE ( 3013): OMXCORE API - OMX_Init
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 0
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.avc
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.avc
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 1
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.mpeg4
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.mpeg4
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 2
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.h263
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.decoder.h263
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 3
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.encoder.mpeg4
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.encoder.mpeg4
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 4
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.encoder.h263
I/QC_CORE ( 3013): GetRolesOfComponent OMX.qcom.video.encoder.h263
I/QC_CORE ( 3013): OMXCORE API - OMX_ComponentNameEnum 159d0 128 5
E/MediaPlayer(10476): start called in state 4
E/MediaPlayer(10476): error (-38, 0)
V/AudioStreamPlayer(10476): playRTSPAudioURL :: media player started!
E/MediaPlayer(10476): Error (-38,0)
I/ActivityManager( 3019): Displayed activity
com.MediaFrameWork/.AudioStreamPlayer: 710 ms (total 710 ms)


Somebody help me? I already saw the media formats supported and
OpenCore have mp3 codec.
Best regards.

-- 

3. Using SQLite in with few activities

4. Android onKey is not fired for soft keyboard on a nexus one

5. Total and free Memory Usage

6. Animated-Rotate

7. Not able list the files using java.io.File.listFiles()