What I'm wanting to do is use the user's input to determine the size of a matrix, then create the appropriate amount of edit texts for them to fill out the elements. I think I know how to add in new edit texts dynamically, but I don't know how to address them, because they have no id since they are being made dynamically.
you can set the index of the EditText as id.
for(int i=0;i<max;i++){
EditText et=new ExitText(this);
//.........
et.setId(i);
}
And call findViewById(0); and so on
Related
How can you generate for eg. 10 buttons in JavaFX Builder? I don't want to insert them manually.
I need this to create a virtual shop. And i want to have N products on a page, but i need text, image, etc for every product and if i don't know how many products i will have i can't put there 10 of them from the start, because maybe i will have more or less and then there will be blank images with no text set. I hope that my question is clear.
I would like to get 1 product from my database and create a textbox and a button for it. If i get 5 objects from my database i would like to create 5 textboxes and 5 buttons and so on.
So say you were to extract the full list of Objects from your database into your running program, then you could write code that looks something like
foreach(Object in Objects) do
MakeTextBox
MakeButton
MakeImage
Insert TextBox, Button and Image
So without ever having used JavaFX in any meaningful way I could hint you towards doing something like this:
//This is the incoming package, I will assume this is a JSONArray for now since it seems obvious enough and I will assume it's called jarray_stock
for(int i = 0; i < jarray_stock.length(); i++){
Button b = new Button();
TextBox t = new TextBox();
Image i = new Image();
parent.add(b);
parent.add(t);
parent.add(i);
}
Now you just have to take that and replace my button textbox image with the actual appropriate classes for JavaFX and replace the parent.add with the actual methods to add that to your Frame or whatever you're actually using.
Of course if you know how many elements you need to generate you can replace jarray_stock.length() with any number you need.
I would like to set the background of edittext per line as opposed to android's block style of setting up the background i.e when a user writes some text, I should get the text entered by a user, split it into lines and set a background color for each line. Check the attached picture for references.
I've not been able to figure out how to achieve the same, please help. This is what I've done so far, thanks in advance.
Desired picture [1]: https://i.stack.imgur.com/LhpTQ.jpg
String allLines = userInput.getText().toString(); // userInput is an edittext field
String[] lines;
String linelimit = "\n";
lines= allLines.split(linelimit);
//this gives the lines in the user input text][1]][1]
Use 2 or more separate TextView/EditText instead. If number of lines are different during execution then add Textview/EditText dynamically in LinearLayout.
It is not possible in any view (that I know of) because there is only one background for every view, or EditText and cannot be separated for each line.
If you are using an EditText that user can edit, then you will have to calculate width of EditText as text changes and if its width exceeds a limit, you can add another EditText below it.
I have a tableview, in one of his columns i calculate the subTotal:
Column "subTotal" = "Qty * price", after calculating the subtotals, i calculate the sum of all subtotals.
Maybe using:
- a label,So How i can store and retrieve the sum from a label as needed.
- Spinner, So How to bind the sum to the Spinner's valueProperty.
Here is the first option using a label:
DoubleBinding doubleBinding = Bindings.createDoubleBinding(() -> tableView.getItems().stream().
collect(Collectors.summingDouble(LineCommand::getSubTotal)), tableView.getItems());
lblTotalHt.textProperty().bind(Bindings.format("%3.2f", doubleBinding));
The problem how i can retreive the stored sum ?
the second option:
How to perform this using a spinner
fldTotalHt.valueProperty().....Bind(toTheSum);
For your first question: "How can I retrieve the stored sum?", you can get this from the binding with
double sum = doubleBinding.getValue();
For the second question, you can do
Spinner<Double> spinner = new Spinner(min, max, doubleBinding.getValue());
spinner.getValueFactory().valueProperty().bind(doubleBinding.asObject());
(asObject() effectively converts the ObservableValue<Number> to an ObservableValue<Double>).
But note that binding a spinner's value is pretty pointless. A bound value cannot be set, for obvious reasons, so the user would not be allowed to change the value of the spinner - this means it would have no more functionality than a label. It's really not clear why you would want to display this value in a spinner, since it really doesn't make any sense for the user to be able to change a value which is computed from other values. Why not just use a label?
If fldTotalHt is a Spinner, then you can access its value property like this
fldTotalHt.getValueFactory().valueProperty().bind(sumProperty)
About a label. I don't quite understand, what you really what. As I understood, you just can't get label's contents. But that's simply label.getText() and it's strange if you know about properties and bindings, but don't know about that.
I've created an app in which a user can can add or delete rows in a tableLayout. Inside of these rows, a user inputs an Academic class name, the letter grade received in the class, and the number of units the class is worth. Then, it calculates the user's gpa.
I'm not sure how I would go about doing this, but I need to save an exact copy of the layout when the user presses the 'save' button that will save every current specific thing. (Eg. number of editTexts, text in the editTexts, number of rows, etc.)
I've researched using SharedPreferences and using SQLite. I'm not sure which one is better for saving multiple specific layouts. Also, I know nothing of using SQLite because I've never used it before, so if that is the best choice, could you post a link or something to a good tutorial? Thanks!
Avoid database access you can just use simple 2d array to Store all your data
Ex:
//Saving info of 1st Layout
String[][] data= new String[4][4];
data[0][0] =editTextno;
data[0][1] =editText;
data[0][2] =noofrows;
data[0][3] =field4;
For saving info of second,third you can similarly change the index no. like data[1] for layout 1,data[2] for layout 2
later you can set this array inside SharedPreference or can create setter getter to store this array and can retrieve the Array for info inputted by user wherever you want
i m new to android .
i m doing my final yr project in android.
Is the any way to use more elements in list view control....
for example: fetch more data frm database and add it at runtime.
the formate may be
text text
text text
text text
text text
etc.....
refer this page for model https://play.google.com/store/apps/details?id=app.diaryfree&feature=search_result#?t=W251bGwsMSwxLDEsImFwcC5kaWFyeWZyZWUiXQ..
(in this page sample image for that application wil be given, like that report i need to display my data.)
is any other control there for that??? how to add runtime more assign more than one element value???
like this
and how to find which row is clicked?
thankz in advance
you can create custom list views to format the listview the way you asked for. And cursors are a good way to fetch data from a database and pass it to a listview. you can use adapters for that.
a sample code for custom list view can be seen here
to find out which item is clicked you need to use onListItemClickListener like given here Android: onListItemClick in Activity