.setText for default input value doesn't work - ?

Put your problem here if it does not fit any of the other categories.

.setText for default input value doesn't work - ?

Postby dlauxx » Mon Mar 12, 2012 7:36 am

Hi, I am trying to provide a default input value for an EditText input field.

Simplified code segment is as follows:-


package xxx.xxx.xxx;
.
.
public class UserInput extends Activity {
private EditText fieldInput;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userinput);

findView();
dataInput();
setListeners(); // code of setListeners() not included here for simplicity
}

private void findViews() {
fieldInput = (EditText)findViewById (R.id.field_input);
}

private void dataInput(){
//
myInput = "1234";
fieldInput.setText(myInput, TextView.BufferType.EDITABLE);
myInput = fieldInput.getText().toString();

}


The "1234" was displayed on the fieldInput View, after back space and type
different text on the input field and hit the button, the System.out.println
of myInput is still "1234".

I notice that while using Preference, it also use the similar .setText method,
but why the above code doesn't work?

Any help would be highly appreciated.
dlauxx
Freshman
Freshman
 
Posts: 4
Joined: Sun Feb 05, 2012 1:18 pm

Top

Re: .setText for default input value doesn't work - ?

Postby vandzi » Mon Mar 12, 2012 9:09 pm

Try to set default value in layout file
vandzi
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jun 11, 2010 11:31 am
Location: Slovakia

Re: .setText for default input value doesn't work - ?

Postby dlauxx » Tue Mar 13, 2012 6:29 am

vandzi wrote:Try to set default value in layout file


Thank you vandzi.

Actually my default values are the present date and time obtained by the
calendar object. So it will change every time when the app is run.

Data input with supplied default values is, I believe, the function that most
Android developers longing for.

Thanks.
dlauxx
Freshman
Freshman
 
Posts: 4
Joined: Sun Feb 05, 2012 1:18 pm

Re: .setText for default input value doesn't work - ?

Postby vandzi » Tue Mar 13, 2012 7:34 am

Do you have this code:
myInput = fieldInput.getText().toString();
in button onclick method?
vandzi
Junior Developer
Junior Developer
 
Posts: 20
Joined: Fri Jun 11, 2010 11:31 am
Location: Slovakia

Re: .setText for default input value doesn't work - ?

Postby nin2246 » Tue Mar 13, 2012 6:11 pm

Code: Select all
findView();
dataInput();
setListeners(); // code of setListeners() not included here for simplicity
}

private void findViews() {
fieldInput = (EditText)findViewById (R.id.field_input);
}


Your findView();
When you call it, it is being called as findViews(); that might also be causing an error
nin2246
Developer
Developer
 
Posts: 42
Joined: Wed Jan 18, 2012 8:08 pm

Re: .setText for default input value doesn't work - ?

Postby Phyll » Tue Mar 13, 2012 9:21 pm

Hi vandzi,

I think we need to see the onclick code to see why it is not setting the output statement from the input edittext.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Top

Re: .setText for default input value doesn't work - ?

Postby albereseanes » Fri Dec 28, 2012 7:37 am

Others break out in a cold sweating just considering having down a chance to complete. Work so rules their lifestyles that they cannot appreciate totally free time at all without sensation accountable that they are not achieving something.
albereseanes
Freshman
Freshman
 
Posts: 5
Joined: Fri Dec 28, 2012 6:22 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Google [Bot] and 19 guests