How to set Title in FragmentDialog with text from Activity?
You can try use arguments to do so:
On your activity:
Bundle arguments = new Bundle();
Fragment fragment = new YourDialogFragment();
arguments.putSerializable(KEYNAME, YOUR_SERIALIZABLE_ITEM);
fragment.setArguments(arguments);
getFragmentManager().beginTransaction().add(R.id.your, fragment).commit();
On your fragment:
if (getArguments().containsKey(KEYNAME))
(ObjectType) getArguments().getSerializable(KEYNAME);
Related
I have a basic question for JavaFX but coudn't figure it out. For HBox, When I'm using getChildren().addAll() for Label and ImageView, I get the following message:
The method addAll(int, Collection<? extends Node>) in the type List<Node> is not applicable for the argument (Label, ImageView[])
I'm not sure what's the issue. I can use normally if its (TextField, ImageView[]), but it doesn't work for (Label, ImageView[]).
This is my simplified code:
ImageView[] imagesRow = new ImageView[2];
Image[] img = new Image[2];
String title = "Result";
img[0] = new Image("sample1.png", 60, 35, true, true);
img[1] = new Image("sample2.png", 60, 35, true, true);
imagesRow[0] = new ImageView();
imagesRow[1] = new ImageView();
imagesRow[0].setImage (img[0]);
imagesRow[1].setImage (img[1]);
Label label = new Label();
label.setText(title + ": ");
// Create horizontal box
HBox box = new HBox();
box.setPadding(new Insets(20, 5 , 2, 50));
box.getChildren().addAll(label, imagesRow); // issue here
May I seek the reason and what should I do instead to align label and image horizontally?
Thanks in advance.
A Collection needs to be of one type (or inheriting from a common parent somewhere in the heirarchy).
A Label is a type of Node and therefore anything else you try to pass as a part of the Collection parameter must also be a Node. An array is obviously not.
In your case, you would need to use two calls to populate the children of the HBox:
box.getChildren().add(label);
box.getChildren().addAll(imagesRow);
The reason you can call addAll(imagesRow) without a problem is because with only the one argument, you're only passing in one Collection, an array.
By calling addAll(label, imagesRow), you're telling Java that you're passing a Collection of one type, but you actually passed it a Node and an array.
I want to convert a label value (Object) to a string variable but I get an empty string.
Here is the code.
var label = new Label
{
};
label.SetBinding(Label.TextProperty, "Link");
string url = label.GetValue(Label.TextProperty).toString();
I want to use the content of the label as a string.
If I don't convert it the url in the label it's ok but when I convert it I get an empty string as result. Any help? How can I convert this to a string?
Thanks in advance.
You can set the Label text implicitely, but I have a feeling that's not what you're trying to do.
If you want to bind to a Link property from a ViewModel, you probably just forgot to set the BindingContext for your Label.
var label = new Label
{
Text = "Set implicitely"
};
string url = label.GetValue(Label.TextProperty).ToString(); // Set implicitely
MyViewModel viewModel = new MyViewModel
{
Link = "Set through binding"
};
label.BindingContext = viewModel;
label.SetBinding(Label.TextProperty, "Link");
string url2 = label.GetValue(Label.TextProperty).ToString(); // Set through binding
Well I found a very easy solution as #hichame.yessou already mentioned on the first comment.
I was passing data into a label by XAML
<Label Text="{Binding Link}" x:Name="linkLabel" IsVisible="False" />
But I put the "x:name" property in order to handle the label from the xaml.cs file.
Well then all was easy..
string url = linkLabel.Text;
In JavaFX is it at all possible to fill a ComboBox with items read from a file? Basically, I have a list of all the street names in a country and I want to display them within my ComboBox as options. Thanks.
Edit:
Finally found some time to actually tackle however I got stuck when it came to loading the array into the combobox. Any help?
This is the method which reads from the file:
private String ReadTownsAndCities(String[] choice){
List<String> list = new ArrayList<>();
String s;
FileReader fr;
BufferedReader br;
try{
fr = new FileReader("TownsAndCities.txt");
br = new BufferedReader(fr);
while((s = br.readLine()) !=null){
list.add(s);
}
choice = list.toArray(new String[list.size()]);
fr.close();
}catch(FileNotFoundException exc){
System.out.println("Cannot open input file.");
}catch(IOException exc){
System.out.println("Error reading file");
}
Now I need to load it into this combobox:
//locality combo box
localityCombo = new ComboBox<>();
//localityCombo.getItems().addAll();
grid.add(localityCombo, 1,11);
Depends on what format does the file have. If it contains many lines and each line is a street name, i would read the file line by line with a WHILE-Loop and for each iteration create a new Item in your ComboBox.
I have a VBox in which many nodes of type Buttonare added.
private final VBox vbox = new VBox();
private final Button b1= new Button("1");
private final Button b2= new Button("2");
private final Button b3= new Button("3");
private final Button b4= new Button("4");
vbox.getChildren().addAll(b1,b2,b3,b4);
Is there a way to cast its child items to Button type.
I need something like this:
ObservableList<Button> children = (ObservableList<Button>) vbox.getChildren();
Yes this is possible, if you use the raw type.
ObservableList<Button> children = (ObservableList)vbox.getChildren();
Note however, that this can easily lead to ClassCastExceptions at runtime, if the types are incorrect or the child list hardcodes the parameter type for a parameter that depends on the type parameter.
im trying to add a new tag to my DicomFile.DataSet in ClearCanvas.
I notice there is the method "DicomFile.DataSet.RemoveAttribute" but no "AddAtribute" method. So I have been looking at the method "LoadDicomFields" & "SaveDicomFields" but so far can't seem to get them to work. Ive tried to pass in a "DicomFieldAttribute" to these methods, but to no avail.
What am I missing here? Or what do I need to do to add a new tag to the DataSet.
DicomFieldAttribute c = new DicomFieldAttribute(tag);
List<DicomFieldAttribute> cs = new List<DicomFieldAttribute>();
cs.Add(c);
DicomFile.DataSet.LoadDicomFields(cs);
DicomFile.DataSet.SaveDicomFields(cs);
if(DicomFile.DataSet.Contains(tag))
{
tag = 0; //BreakPoint never reached here
}
Or I tried this as well::
DicomFieldAttribute c = new DicomFieldAttribute(tag);
DicomFile.DataSet.LoadDicomFields(c);
DicomFile.DataSet.SaveDicomFields(c);
if(DicomFile.DataSet.Contains(tag))
{
tag = 0; //BreakPoint never reached here
}
Ive been stuck on what would seem to be a trivial task.
You're confusing a bit the use of attributes. The DicomFiledAttribute is a .NET attribute that can be placed on members of a class so that the class is automatically populated with values from a DicomAttributeCollection or or to have the class automatically populated with values from the DicomAttribute Collection. Ie, given a test class like this:
public class TestClass
{
[DicomField(DicomTags.SopClassUid, DefaultValue = DicomFieldDefault.Default)]
public DicomUid SopClassUid = null;
[DicomField(DicomTags.SopInstanceUid, DefaultValue = DicomFieldDefault.Default)]
public DicomUid SOPInstanceUID = null;
[DicomField(DicomTags.StudyDate, DefaultValue = DicomFieldDefault.Default)]
public DateTime StudyDate;
}
You could populate an instance of the class like this:
DicomFile file = new DicomFile("filename.dcm");
file.Load();
TestClass testInstance = new TestClass();
file.DataSet.LoadDicomFields(testInstance);
// testInstance should now be populated with the values from file
If you're interested in just populating some DICOM tags, the DicomAttributeCollection has an indexer in it. The indexer will automatically create a DicomAttribute instance if it doesn't already exist, for the tag requested via the indexer. So, to populate a value, you can do soemthing like this:
DicomFile file = new DicomFile("filename.dcm");
file.DataSet[DicomTags.SopInstanceUid].SetStringValue("1.1.1");
If you want to create the DicomAttribute yourself, you can do something like this:
DicomAttribute attrib = new DicomAttributeUI(DicomTags.SopInstanceUid);
attrib.SetStringValue("1.1.1");
DicomFile file = new DicomFile("filename.dcm");
file.DataSet[DicomTags.SopInstanceUid] = attrib;