I have asked similar question elsewhere but I'm posting a new question.
I wanted layout like this
txt[1] tv[1]
txt[2]tv[2]
...
txt[8] tv[8]
My Attepmt, the main lane is this:
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
but it doesn't work.
My code
public void click2(View view) {
Button button3 = findViewById(R.id.button2);
button3.setText("hello");
// Put buttons into an array
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.activity_main);
// GridLayout gridLayout=(GridLayout) findViewById(R.id.activity_main);
// Put buttons into an array
// Button[] txt = {new Button(this), new Button(this)};
Button[] txt = new Button[8];
TextView[] tv = new TextView[8];
// loop over all values of i between 0 to the end of the button array
for (int i = 0; i < txt.length; i = i + 1) {
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// Access array elements by index so txt1 is txt[1], etc.
txt[i]=new Button(this);
txt[i].setText(Integer.toBinaryString(i));
linearLayout.addView(txt[i]);
tv[i]=new TextView(this);
linearLayout.addView(tv[i]);
}
};
Related
In my project I'm using javafx and there is a TableView in which there are four columns i.e source, target, score, date and I want either a single word in the column or the whole row to be bold or italic and to change the font size.
public void readtextfile(String data) //data contains the location of the file
{
data1 = FXCollections.observableArrayList();
tab = new Tab("new" + (tabPaneTableview.getTabs().size() + 1));//create a new tab every time loaddatabase() is called
tabPaneTableview.getTabs().add(tab);//tab is added in tabpane
tabPaneTableview.getSelectionModel().select(tab);//the particular tab is selected
tv_new = new TableView<>();
tc_id = new TableColumn<File, Integer>("Id");
tc_source = new TableColumn<File, String>("Source");
tc_target = new TableColumn<File, String>("Target");
tc_score = new TableColumn<File, String>("Score");
// tcUsername=new TableColumn<File,String>("Creation User");
//tcCurrentdate=new TableColumn<File,String>("Date/Time");
tcNote = new TableColumn<File, String>("Note");
tcStatus = new TableColumn<File, String>("Status");
//tcConfirm=new TableColumn<File,String>("Confirm");
//tcLock=new TableColumn<File,String>("Lock");
//tcStatus.getColumns().addAll(tcConfirm,tcLock);
//tcPostag=new TableColumn<ExcelFile,String>("Pos Tag");
tv_new.getColumns().addAll(tc_id, tc_source, tc_target, tc_score, tcNote, tcStatus);
tab.setContent(tv_new);
tv_new.setPrefHeight(250);
tv_new.setRowFactory(new Callback<TableView<File>, TableRow<File>>() {
#Override
public TableRow<File> call(TableView<File> param) {
final TableRow<File> row = new TableRow<File>() {
#Override
protected void updateItem(File row, boolean empty) {
super.updateItem(row, empty);
if (!empty)
styleProperty().bind(Bindings.when(row.selectedProperty())
.then("-fx-font-weight: bold; -fx-font-size: 16;")
.otherwise(""));
}
};
return row;
}
});
public boolean getSelected() {return selected.get();}
public BooleanProperty selectedProperty(){return selected;}
I'm using this code but it doesn't yield the desired result.
Maybe this is not the solution that you are looking for but this might help you.
.table-row-cell:hover {
-fx-border-color: red; /* Vertical Lines*/
-fx-control-inner-background: #c1c1c1;
-fx-border-width: 1;
}
This is a fragment of code that I have provided because I think that changing the text font, just selecting a row is a bit complicated because you have to keep in mind that the text is linked by the column or cell that is focused.
This piece of code has to be included in the css file and from sceneBuilder or from the code you have to include the stylesheet. Good luck.
Using Xamarin.Forms, how do I get the same effect as the application pictured below, specifically to show a centred image on the Action Bar / page tool bar (the section in a blue box)?
I would like to have a long width image in that section, and the solution must work for Android, iOS, Windows Phone, and Universal Windows (even if it means writing custom renderers or platform specific xamarin code).
I suggest you create your own Xamarin.Forms view and handle the navigation by yourself something similar to this:
public class CustomBackNavigationBar : StackLayout
{
public Image BackIcon;
public Image Icon;
public Label IconTitle;
public StackLayout IconContainer;
public CustomBackNavigationBar(string title, string icon)
{
Padding = new Thickness(15,5);
HeightRequest = 40;
Orientation = StackOrientation.Horizontal;
VerticalOptions = LayoutOptions.Start;
BackgroundColor = StaticData.BlueColor;
Spacing = 15;
BackIcon = new Image
{
Source = StaticData.BackIcon,
HorizontalOptions = LayoutOptions.Start
};
Label Title = new Label
{
Text = title,
TextColor = Color.White,
FontSize = Device.GetNamedSize(NamedSize.Default, typeof(Label)),
FontAttributes = FontAttributes.Bold,
VerticalTextAlignment = TextAlignment.Center
};
Icon = new Image
{
Source = icon
};
IconTitle = new Label
{
Text = StaticData.CallAgent,
TextColor = Color.White,
FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),
};
IconContainer = new StackLayout
{
HorizontalOptions = LayoutOptions.EndAndExpand,
Spacing = 2,
Children = { Icon, IconTitle }
};
Children.Add(BackIcon);
Children.Add(Title);
Children.Add(IconContainer);
#region Events
BackIcon.GestureRecognizers.Clear();
BackIcon.GestureRecognizers.Add(new TapGestureRecognizer
{
Command = new Command(PopAsync)
});
#endregion
}
async void PopAsync()
{
await App.AppNavigation.PopAsync();
}
}
I'm developing an taxi caller app. And I used Bing map
This is my flow:
Get my position
Get 3 near taxis
When I tap 1 in 3 taxis, all in formation of taxis will sent to a new
Variable to used with another function.
This is my code
And how to send a obj from Foreach to taxiIcon_Tap?
Thanks and best regards!
//------ BEGIN get near Driver ------//
private async void GetNearDriver()
{
var uid = userData.content.uid;
var lat = pickupLat;
var lng = pickupLng;
var clvl = taxiType;
var input = string.Format("{{\"uid\":\"{0}\",\"lat\":{1},\"lng\":{2},\"cLvl\":\"{3}\"}}", uid, lat.ToString().Replace(',', '.'), lng.ToString().Replace(',', '.'), clvl);
var output = await GetJsonFromPOSTMethod.GetJsonString(ConstantVariable.tNetRiderGetNerDriverAddress, input);
var nearDriver = JsonConvert.DeserializeObject<RiderGetNearDriver>(output);
if (nearDriver.content.listDriverDTO.Count > 0)
{
foreach (var taxi in nearDriver.content.listDriverDTO)
{
ShowNearDrivers(taxi.lat, taxi.lng, taxi.cName);
}
}
}
//------ END get near Driver ------//
//------ BEGIN show and Design UI 3 taxi near current position ------//
private void ShowNearDrivers(double lat, double lng, string tName)
{
GeoCoordinate TaxiCoordinate = new GeoCoordinate(lat, lng);
//Create taxi icon on map
Image taxiIcon = new Image();
taxiIcon.Source = new BitmapImage(new Uri("/Images/Taxis/img_CarIcon.png", UriKind.Relative));
//Add a tapped event
taxiIcon.Tap += taxiIcon_Tap;
//Create Taxi Name
TextBlock taxiName = new TextBlock();
taxiName.HorizontalAlignment = HorizontalAlignment.Center;
taxiName.Text = tName;
taxiName.FontSize = 12;
taxiName.Foreground = new SolidColorBrush(Color.FromArgb(255, (byte)46, (byte)159, (byte)255)); //RBG color for #2e9fff
//Create Stack Panel to group icon, taxi name, ...
Rectangle taxiNameBackground = new Rectangle();
taxiNameBackground.Height = 18;
taxiNameBackground.Width = taxiName.ToString().Length + 20;
taxiNameBackground.RadiusX = 9;
taxiNameBackground.RadiusY = 7;
//taxiNameBackground.Stroke = new SolidColorBrush(Color.FromArgb(255, (byte)171, (byte)171, (byte)171)); //RBG color for #ababab
taxiNameBackground.Fill = new SolidColorBrush(Color.FromArgb(255, (byte)213, (byte)235, (byte)255)); //RBG color for #d5ebff
Grid taxiNameGrid = new Grid();
taxiNameGrid.Margin = new Thickness(0, 4, 0, 4); //Margin Top and Bottom 4px
taxiNameGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Center;
taxiNameGrid.VerticalAlignment = System.Windows.VerticalAlignment.Center;
taxiNameGrid.Children.Add(taxiNameBackground);
taxiNameGrid.Children.Add(taxiName);
StackPanel taxiStackPanel = new StackPanel();
//taxiStackPanel.Margin = new Thickness(5, 0, 5, 0);
taxiStackPanel.Children.Add(taxiIcon);
taxiStackPanel.Children.Add(taxiNameGrid);
// Create a MapOverlay to contain the circle.
MapOverlay myTaxiOvelay = new MapOverlay();
//myTaxiOvelay.Content = myCircle;
myTaxiOvelay.Content = taxiStackPanel;
myTaxiOvelay.PositionOrigin = new Point(0.5, 0.5);
myTaxiOvelay.GeoCoordinate = TaxiCoordinate;
//Add to Map's Layer
riderMapLayer = new MapLayer();
riderMapLayer.Add(myTaxiOvelay);
map_RiderMap.Layers.Add(riderMapLayer);
}
//Tapped event
private void taxiIcon_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
//Hide Step 01
this.grv_Step01.Visibility = Visibility.Collapsed;
//Show Step 02
this.grv_Step02.Visibility = Visibility.Visible;
this.grv_Picker.Visibility = Visibility.Collapsed;
//Step 2 info
LoadStep2Info();
}
//------ END show and Design UI 3 taxi near current position ------//
You can use the Tag property to pass such miscellaneous objects around when using events which don't expose the ability to add an additional payload.
My understanding is that in the taxiIcon_Tap event you want to be able to access your own object that is related to whatever was tapped.
To do this set you object to the Tag property of the item being tapped.
i.e. If you want to pass the coordinates do:
taxiIcon.Tag = TaxiCoordinate;
(You could pass anything.)
Then, in the tapped event handler you can get at this object by casting from the sender to get the Tag and then casting that back to your type.
var coords = ((FrameworkElement)sender).Tag as GeoCoordinate;
I want to open a Popover in code after a specific action happens (e.g. tap on a button).
The following Code let me open a Popover with a NavigationBar but it don't looks like the one I've done with IB. (IB approach was embedding a UIViewController in a UINavigationController and defining the the two buttons cancel and save). The only thing I want is having these two buttons on top of the Popover. I don't use any navigation functionality!
var cell = grid.VisibleCellAtCoordinate(coordinate) as SDataGridTextCell;
var viewController = new UIViewController();
var navBar = new UINavigationBar(new RectangleF(0, 0, viewController.View.Bounds.Width, 50))
{
AutoresizingMask = UIViewAutoresizing.FlexibleWidth,
BarStyle = UIBarStyle.Black,
Translucent = true,
Items = new[]
{
new UINavigationItem("test")
{
LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (s, e) => { _popoverController.Dismiss(true); }),
RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Save, (s, e) => { _popoverController.Dismiss(true); })
}
}
};
var textField = new UITextField(new RectangleF(0, 50, viewController.View.Bounds.Width, viewController.View.Bounds.Height)) { Placeholder = "Mein Text...", BackgroundColor = UIColor.White };
textField.BecomeFirstResponder();
viewController.View.Add(navBar);
viewController.View.Add(textField);
viewController.View.SubviewAdded(textField);
_popoverController = new UIPopoverController(viewController);
_popoverController.SetPopoverContentSize(new SizeF(250, 200), false);
_popoverController.PresentFromRect(cell.Bounds, cell, UIPopoverArrowDirection.Any, false);
These buttons looks like this image (ugly):
And this image shows how it's look like when created in IB:
That's one of the caveats of using a standalone navigation bar in a popover. Embedding your view controller in a navigation controller is, as far as I know, the only way to avoid it.
Had some problem embedding the content view (UIViewController) correctly to the UINavigationController because I tried to add the navigation bar items (buttons) each time directly to the UINavigationController's NavigationItem property. But this must be done through the content view controller...
var contentViewController = new UIViewController();
var textField = new UITextField(contentViewController.View.Bounds)
{
BackgroundColor = UIColor.White,
AutoresizingMask = ~UIViewAutoresizing.None,
Placeholder = "My Text..."
};
contentViewController.View.Add(textField);
var navigationController = new UINavigationController(contentViewController);
contentViewController.Title = "Popover";
contentViewController.NavigationItem.LeftBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Cancel, (s, e) => { _popoverController.Dismiss(false); });
contentViewController.NavigationItem.RightBarButtonItem = new UIBarButtonItem(UIBarButtonSystemItem.Save, (s, e) => { _popoverController.Dismiss(false); });
_popoverController = new UIPopoverController(navigationController);
_popoverController.SetPopoverContentSize(new SizeF(300, 300), false);
_popoverController.PresentFromRect(button1.Bounds, button1, UIPopoverArrowDirection.Any, false);
given the following code, I am having an issue when clicking on each element. If we assume I have 5 exercises and therefore create 5 elements in the foreach() loop, when the table is rendered and I click on any element, the delegate always gets the exercise of the 5th (last) element.
The elements are displayed properly, each showing the associated exercise's name. It is just the delegate that does not work as expected.
If I do not use a foreach loop and hardcode each element instead it works as expected. However if I cannot dynamically populate the dialogViewController and use the element tapped event for each one, is not good.
private void CreateExerciseTable()
{
Section section = new Section();
foreach (var exercise in exercises)
{
var element = new StyledStringElement(exercise.ExerciseName,
delegate { AddExercise(exercise); })
{
Font = Fonts.H3,
TextColor = UIColor.White,
BackgroundColor = RGBColors.LightBlue,
Accessory = UITableViewCellAccessory.DisclosureIndicator
};
section.Elements.Add(element);
}
var root = new RootElement("Selection") {
section
};
var dv = new DialogViewController(root, true);
dv.Style = UITableViewStyle.Plain;
//Remove the extra blank table lines from the bottom of the table.
UIView footer = new UIView(new System.Drawing.RectangleF(0,0,0,0));
dv.TableView.TableFooterView = footer;
dv.TableView.SeparatorColor = UIColor.White;
dv.TableView.BackgroundColor = UIColor.White;
tableFitnessExercises.AddSubview(dv.View);
}
private void AddExercise(FitnessExercise exercise)
{
NavigationManager.FitnessRoutine.Add(exercise);
PerformSegue(UIIdentifierConstants.SegAddExerciseToFitnessRoutine, this);
}
This is a classic closure bug!
The problem is that you are accessing the loop reference.
Try:
foreach (var exercise in exercises)
{
var localRef = exercise;
var element = new StyledStringElement(exercise.ExerciseName,
delegate { AddExercise(localRef); })
{
Font = Fonts.H3,
TextColor = UIColor.White,
BackgroundColor = RGBColors.LightBlue,
Accessory = UITableViewCellAccessory.DisclosureIndicator
};
section.Elements.Add(element);
}
For more on this see http://blogs.msdn.com/b/ericlippert/archive/2009/11/12/closing-over-the-loop-variable-considered-harmful.aspx