I am trying to set the text when I press the save button. But when I return to the view the text is faint grey.
Initial view on Message Settings
Updated view on Message Settings before I save
Updated view on Message Settings after I save and return to the view.
The source code for my SetupMessageFragment.java is here https://github.com/jackygrahamez/MayDay/blob/gradle2/app/src/main/java/com/mayday/md/fragment/SetupMessageFragment.java
There is a Log for the text retrieved from the sharedPreferences. I can see the new text vs the current textview text:
Fragment fragment2 = getChildFragmentManager().findFragmentById(R.id.sms_message);
((MessageTextFragment) fragment2).setActionButtonStateListener(bAction);
smsEditText = (EditText) fragment2.getView().findViewById(R.id.message_edit_text);
Log.e(">>>>", "onActivityCreated smsEditText "+smsEditText.getText().toString());
String currentMsg = SMSSettings.retrieveMessage(activity);
Log.e(">>>>", "onActivityCreated currentMsg "+currentMsg);
if(currentMsg != null) {
displaySettings(currentMsg);
}
Then the logcat
02-14 16:55:33.366 29043-29043/com.mayday.md E/>>>>﹕ onActivityCreated smsEditText I need IMMEDIATE help!
02-14 16:55:33.366 29043-29043/com.mayday.md E/>>>>﹕ onActivityCreated currentMsg I need IMMEDIATE help! Foo bar
Define black color in colors.xml (<color name="black" value="#000000"/>)
Set the Edit Text color to black.
smsEditText = (EditText) fragment2.getView().findViewById(R.id.message_edit_text);
smsEditText.setTextColor(getActivity().getResource().getColor(R.color.black));
Yo can edit the color in your colors.xml file, but as you want to use black color, which is already defined by android, you could just do this:
smsEditText = (EditText) fragment2.getView().findViewById(R.id.message_edit_text);
smsEditText.setTextColor(Color.BLACK);
Related
The app crashes when the button is selected which uses the values converted from edit texts. Tried multiple ways to move the part edittext = R.ids .. to try and make sure the edittexts picks new values after the oncreate first runs.
Think the calculation part causes the crash because its trying to perform a calculation with stored values from the edit text when the value is false from the first time the edit text gets the R.ids... in the onCreate method.
needed hide/display editText based off a radio button setonCheckedChangeListener in the onCreate method. So edittext = R.ids .. set in this method, the app does not crash at runtime like it would if I moved the edittext = R.ids .. to the testFunction method.
EditText editTextValue;
EditText editTextValue2;
double amount;
protected void onCreate(){...
//Get edittext field parameters
editTextValue = (EditText) findViewById(R.id.editText_weight_kg);
//listener to switch editTexts on which radio button selected in units group
unitsRG.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (checkedId == R.id.imperial) {
editTextValue2.setVisibility(View.VISIBLE);
editTextValue.setVisibility(View.GONE);
}
void testFunction(View view){
String stringValue = editTextValue..getText().toString();
//check value as long as its not empty for the edit text , save it
if (editTextValue.getText().length() > 0) {
amount = Integer.parseInt(stringValue);
Log.e("MainActivity", " " + amount);
}
}
but now when I run the app I get this error in the long cat
enter image description here
E/ClipboardServiceEx﹕ clipEx is android.sec.clipboard.ClipboardExManager#1f70b420
E/ClipboardServiceEx﹕ clipEx has text data : false
here is the xml for one of the edit texts
<EditText
android:id="#+id/editText_weight_lb"
style="#style/EditTextViewStyle"
android:visibility="visible"/>
In the editTextStyle , I set the textCursorDrawable to null to try and have different colors for the pointer and underline colors. Not sure if this could also be affecting the editTextView storing the value
<item name="android:textCursorDrawable">#null</item>
I also tried setting edittext = R.ids in the testfunction and in the onCreate method. See if the editTexts would store the values the user enters rather than keeping the empty values when onCreate initially run.
I still got the same clipEx has text data:false error after trying this.
I searched the logcat error "clipEx has text data: false" and found something regarding samsung memory leaks.
https://github.com/square/leakcanary/issues/133
I am using a samsung galaxy for testing. I feel the issue is more with where I'm setting the edittexts to the R.ids thats causing the issue.
I saw the post for checking to make sure valid value entered for edittext.
Issue with empty EditText
How to Check whether a value is entered in editexts before submitting?
will add the check after finding out why values are not getting stored/ still remaining false.
Thanks
well I tried a different approach to implement the method.
I placed a button in the OnCreate method to define the event handlers against the buttons:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button calculate = (Button)findViewById(R.id.calculate);
calculate.setOnClickListener(new View.OnClickListener(){
String stringValue = editTextValue.getText().toString();
//check value as long as its not empty for the edit text , save it
if (editTextValue.getText().length() > 0) {
amount = Integer.parseInt(stringValue);
Log.e("MainActivity", " " + amount);
}
.....
.....
}
}
By using the button method in the OnCreate, when I ran the app, errors would actually come up on the Integer.parseInt() method call. Turns out that even though the editTexts that I was entering text for did not have text values, the other editTexts still had strings for the text, so this would cause the app to crash.
<EditText...
android:text="kg"/>
I took out the text values. It worked again.
I also took out this line in the style sheet for the editText. This was to change the editText border color, cursor color, or line.
<item name="android:textCursorDrawable">#null</item>
I tried the public void testFunction() approach which I had used before, the app works, but the clipEx has text data : false continues to show up.
But the app works now with either the Button method in onCreate or as a public void testFunction() approach.
I have extended EditTextPreference, but the Dialog Message won't display. This happens if I add the dialogMessage programatically or in the the preferences.xml.
Here is my onBindDialogView:
AutoCompleteTextView editText = mEditText;
editText.setText(getText());
ViewParent oldParent = editText.getParent();
if (oldParent != view) {
if (oldParent != null) {
((ViewGroup) oldParent).removeView(editText);
}
onAddEditTextToDialogView(view, editText);
}
Is the dialog message really absent? It's probably there but its text color might make it less (or not) visible. (Or try to dismiss software keyboard). Try experimenting with dialog messages having a number of "\n" characters and see if that affects dialog layout. If so, it means the dialog message is actually there but camouflaged too well.
EditTextPreference brings a text view (in the preference_dialog_edittext.xml) that replaces the existing one (in the alert_dialog.xml) for the dialog message, but unfortunately with different text style, which might cause a visibility problem under certain themes. Even their sizes are different.
One solution might be to obtain the text color and size from the original text view to be replaced and apply them to the new one, but I would suggest retaining the original text view instead, because it's more likely to be visually consistent if there are any future UI changes. Try adding the following overrides
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
super.onPrepareDialogBuilder(builder);
builder.setMessage(getDialogMessage()); // bring back the original text view
}
protected void onAddEditTextToDialogView(View dialogView, EditText editText) {
int id = getContext().getResources().getIdentifier("edittext_container", "id", "android");
ViewGroup container = (ViewGroup) dialogView.findViewById(id);
container.removeAllViews(); // remove the new text view
super.onAddEditTextToDialogView(dialogView, editText);
}
If you think the dialog message and the edittext view is too far apart, they can be brought together a little closer by adding another override:
protected void showDialog(Bundle state) {
super.showDialog(state);
int id = getContext().getResources().getIdentifier("message", "id", "android");
TextView message = (TextView) getDialog().findViewById(id);
message.setPadding(message.getPaddingLeft(), message.getPaddingTop(), message.getPaddingRight(), 0);
}
and add the following line in the onAddEditTextToDialogView method after calling removeAllViews:
container.setPadding(container.getPaddingLeft(), 0, container.getPaddingRight(), container.getPaddingBottom());
I have to get a EditText object which is nothing but a search bar in app with text visible as Current Location, however if I've already made a search query with myText, there is no Current Location text visible and search bar shows myText.
I am writing the test cases using Robotium solo object.
How can i write a conditional statement to get the EditText despite of what text it shows. Something like
if !found solo.getText("Current Location")
search solo.getText("myText");
This is what I am doing currently
EditText text = (EditText) solo.getText("Current Location");
if(text == null){
text = (EditText) solo.getText("myText");
//my rest of the code goes here....
But this throws exception if Current Location is not present in the search bar.
junit.framework.AssertionFailedError: TextView with text: 'Current Location' is not found!
Please suggest the correct way.
Try with this code:
if(!solo.searchText("Current Location"))
assertTrue(solo.searchText("my Text"))
else
assertTrue(solo.searchText("Current Location"));
EditText view = (EditText) solo.getView(view1);
if(view == null){
view = (EditText) solo.getView(view2)
}
view.getText().toString();
I have an edit text which I validate. If the data entered does not corespond to the format, I set the background to red, when it coresponds I set it back to light gray, but the rectangle disappears.
I was wondering if I could reset it's properties to their orignal values when the data entered has the correct format.
This is what i am doing now
EditText name = (EditText) findViewById(R.id.Name);
if (name.getText().length() < 1)
{
error = true;
unit.setBackgroundColor(Color.RED);
}
else
{
//instead of this line reset edittext properties
unit.setBackgroundColor(Color.LTGRAY);
}
You can use PorterDuff instead - it has a clear method: http://developer.android.com/reference/android/graphics/PorterDuff.Mode.html.
To set the color:
name.getBackground().setColorFilter(Color.RED, PorterDuff.Mode.SRC_IN);
To remove the color:
name.getBackground().clearColorFilter();
You can try:
editText.setText("");
I'd recommend using the setError() method, which displays an error message above the EditText and removes it automatically when the contents of the EditText change. This is a standard way to show the user that the validation has failed.
You are changing the EditText background so you are overriding android's default background.
you need to manually change it to some other background.
you can save it by Using the getBackground() method in EditText.
You can save the status of the editText before to change it, and restore when you need:
private Drawable originalDrawable;
EditText name = (EditText) findViewById(R.id.Name);
if (name.getText().length() < 1) {
if (originalDrawable == null) {
originalDrawable = unit.getBackground();
}
error = true;
unit.setBackgroundColor(Color.RED);
}
else {
//reset editText
text.setBackgroundDrawable(originalDrawable);
}
I want to get the user input for the EditText view and display it on the screen through TextView when the Button is clicked. I also, want to know what modifications can be done on the string.xml file to do this.
I didn't get the second question, maybe you can elaborate...but for your first query.
String content = edtEditText.getText().toString(); //gets you the contents of edit text
tvTextView.setText(content); //displays it in a textview..
I'm just beginner to help you for getting edittext value to textview. Try out this code -
EditText edit = (EditText)findViewById(R.id.editext1);
TextView tview = (TextView)findViewById(R.id.textview1);
String result = edit.getText().toString();
tview.setText(result);
This will get the text which is in EditText Hope this helps you.
EditText ein=(EditText)findViewById(R.id.edittext1);
TextView t=new TextView(this);
t.setText("Your Text is="+ein.getText());
setContentView(t);
bb.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View view)
{
String s1=tt.getText().toString();
tv.setText(s1);
}
}
);
First get the text from edit text view
edittext.getText().toString()
and Store the obtained text in a string, say value.
value = edittext.getText().toString()
Then set value as the text for textview.
textview.setText(value)
yesButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
eiteText=(EditText)findViewById(R.id.nameET);
String result=eiteText.getText().toString();
Log.d("TAG",result);
}
});
Easiest way to get text from the user:
EditText Variable1 = findViewById(R.id.enter_name);
String Variable2 = Variable1.getText().toString();
in "String.xml" you can notice any String or value you want to use, here are two examples:
<string name="app_name">My Calculator App
</string>
<color name="color_menu_home">#ffcccccc</color>
Used for the layout.xml: android:text="#string/app_name"
The advantage: you can use them as often you want, you only need to link them in your Layout-xml, and you can change the String-Content easily in the strings.xml, without searching in your source-code for the right position.
Important for changing language, you only need to replace the strings.xml - file
Use the following code when clicked on the button :
String value = edittext.getText().toString().trim(); //get text from editText
textView.setText(value); //setText in a textview
Hope to be useful to you.
Try this->
EditText text = (EditText) findViewById(R.id.text_input);
Editable name = text.getText();
Editable is the return data type of getText() method it will handle both
string and integer values
First get the value from edit text in a String variable
String value = edttxt.getText().toString();
Then set that value to textView
txtview.setText(value);
Where edttxt refers to edit text field in XML file
and txtview refers to textfield in XML file to show the value