TextView adding a variable string and appending another - android-edittext

I am using IntentExtra to pass three variables from an entry in a RecyclerView from one Activity into a TextView on another Activity (ActivityTwo) using Get Extras. That all works fine and the variables are joined and displayed in the TextView.
TextView mTitle = (TextView) findViewById(R.id.textViewOrderList);
mTitle.append(number + title + (Double) price);
I then navigate back to ActivityOne, select a different item in the RecyclerView and the new variables are sent to ActivityTwo.
However, despite using append, it either a/ overwrites the existing text, OR b/the first set of text is not retained. Am not sure which
I did consider saving the text to a local file and then appending to it each time I enter ActivityTwo. Then loading it into the TextView But this feels like using a steamroller to crack a nut!!
Any solutions much appreciated.

In the end I decided to write to a local file. As I wanted to Append info rather than overwrite I used the MODE_APPEND rather than MODE_PRIVATE.
try {
FileOutputStream fOut = openFileOutput(fileTitle,MODE_APPEND);
fOut.write(dataTitle.getBytes());
fOut.write('\n');
fOut.close();
Toast.makeText(getBaseContext(),"file saved",Toast.LENGTH_SHORT).show();
}
catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});

Related

It doesn't always scroll to the same place, Appium Android

I am using the following method while scrolling android. but It doesn't always scroll to the same place, even though it's on the same page. what would be the reason.
public void ScrollToCampaignNotice(){
try {
getDriver().findElement(AppiumBy.androidUIAutomator(
"new UiScrollable(new UiSelector().scrollable(true)).flingToEnd(35)"));
} catch (InvalidSelectorException e) {
// ignore
}
}
At the same time, I tried the following method differently, it has the same problem.
You could scroll to exact element instead of flinging 35 times.
Here is an example how to scroll to specific text that is visible:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains("<include your text>").instance(0))
You can also scroll to an element that has specific id like this:
new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId("<insert element ID here>").instance(0))

How can a string control be added in a form during run time?

I want to add a string control on a form during run time when a button is clicked.
What I have tried so far:
Created a form
Added run form method
Added runTimeControl_validate form method
Added button on the form
The button has the following code in its clicked method:
void clicked()
{
FormBuildDesign design = Form.design();
FormBuildGroupControl formBuildGroupControl;
FormStringControl c;
FormControlType fC;
;
// c = addGroup.addControl(FormControlType::String, 'RunTimeControl');
c = ButtonGroup.addControl(fC::String, 'test');
c.label("New control");
formBuildGroupControl = formBuildDesign.control(addGroup.id());
}
I am getting error in the line c = ButtonGroup.addControl(fC::String, 'test');
Error: Enumeration doesn't exist
Firstly, replace fC::String with FormControlType::String.
Secondly, string controls cannot be added to button groups (ButtonGroup control type) - add it to a normal Group instead.
Thirdly, to avoid such issues as missing labels, etc., it makes sense to add element.lock(); before adding the control and element.unlock(); after updating its label. - ignore this.

How to load a web page in a WebView by clicking on a button in other stage?

i'm working on a browser with JavaFX i want to load a web page in FXMLFile1 contains WebView just by clicking on Button in FXMLFile2 to show the page in FXMLFile1 i tried this code :
#FXML
public void tabfirst (ActionEvent ee) throws IOException { //for the FXMLFile2's button text.
Socket socket = new Socket();
try {
//open cursor
panoo.setCursor(Cursor.WAIT);
que.setCursor(Cursor.WAIT);
bbb.setCursor(Cursor.WAIT);
//do work
WebEngine myWebEngine = web1.getEngine(); //this web view is in FXMLFile1
myWebEngine.load("https://www.google.com");
}
catch (IOException e){
final Stage stg = new Stage();
stg.initModality(Modality.APPLICATION_MODAL);
stg.initOwner(stg);
stg.setTitle("Cannot connect to the internet /n Please Verify your connection internet");
labelno.setText("Cannot connect to the internet...");
//set cursor
ancpa.setCursor(Cursor.DEFAULT);
} finally{
try{ socket.close(); } catch (Exception e){ }
}
}
note this class tabfirst is in the Button in the FXMLFile2 and the two FXMLfiles are in the same controller.
so please can any body show me what's wrong with my code and thanks in advance!
I don't think you are setting web1. I think that because the 2 FXML files are using the same controller (Edit: my bad, I misread/misunderstood) you are expecting that they are automatically sharing variables, which they do not !
When the FXMLLoader loads an FXML file it creates a new instance of the controller every time. So the controller instance from FXMLfile1 doesn't know about the controller instance of FXMLfile2 or any of its variables.
There are about 5 different ways of sharing information between controllers:
The simplest is just using getters and setters between the two.
Also fairly simple is to bind properties between the two.
You could setup listeners and then notify them of changes.
Use a messaging bus.
Use injection.
Which one you use depends on various factors and requires more information as to what you are trying to accomplish ?
A basic outline of options 1 & 2 would look something like this:
FXMLLoader fxml1 = .....
fxml1.load();
ctrl1 = fxml1.getController();
FXMLLoader fxml2 = .....
fxml2.load();
ctrl2 = fxml2.getController();
ctrl2.set????( ctrl1.get????() ); // get something from the one and set it in the other
// if the value in ctrl1 changes it does not necessarily change in ctrl2
ctrl2.property????().bind( ctrl1.property???? ); // ctrl2 binds to a property in ctrl1
// if the value of the ctrl1 property changes it WILL also change in ctrl2

Update a text field in BB OS 6 when a listener method is invoked

For the GUI portion of my app, how could I update the RichTextField when my batteryStatusChange method is invoked that changes on the spot?
I was thinking of calling a set method and then having RichTextField get that new number, but it will make a long list of lines unless I delete the textfield before I add a new one.
Something like the battery percentage number under Device Information or the signal strength that changes on the spot.
Edit: Figured it out using setText
public void batteryStatusChange(int status)
{
// TODO Auto-generated method stub
if ((status & DeviceInfo.BSTAT_LEVEL_CHANGED) != 0)
{
batteryStatusField.setText(getBatteryLevel());
}
}
batteryStatusField.setText(getBatteryLevel());
public String getBatteryLevel() {
return Integer.toString(DeviceInfo.getBatteryLevel()) + " %";
}
Got it to work with this code above by putting it inside my batteryStatusChange listener function. Later I will add in more parameters after the function getBatteryLevel() to keep my default formatting.
My battery app in progress

Working with textarea

How can I work with textareas using watin? There is no function like "browser.TextArea(...)".
Is there another name for textareas? I only need to find it and work with rows/cols.
Use the TextField method to access a TextArea.
From the Watin Homepage (modified for this question)
[Test]
public void SearchForWatiNOnGoogle()
{
using (var browser = new IE("http://www.google.com"))
{
// If there was a TextArea with the name q - the next line would get the TextArea object and assign it to the textField variable.
var textField = browser.TextField(Find.ByName("q"));
// Do what you need to do with the TextArea, for example, get the text from the textArea:
string textAreaText = textField.Value;
}
}
Just came across this myself. I thought I would post a more complete answer for people that are still stumped by this. Just use the GetAttributeValue method on the TextField instance like so:
TextField field = Document.TextField(Find.ByName("comments"));
Assert.AreEqual("10", field.GetAttributeValue("rows"));
Assert.AreEqual("42", field.GetAttributeValue("cols"));

Resources