I am getting a Android.Content.ActivityNotFoundException: when I want to go to another activity.
Also I have to recreate my emulator every time I want to see my app because it causes always adb error the second time I start the emulator.
I read that this can be caused by another exception, but I checked a other code and I didnt find anything
Button btnentrar = FindViewById<Button>(Resource.Id.createlist);
btnentrar.Click += delegate
{
StartActivity(typeof(listeditorclass));
};
//activity:
private List<string> mItems;
private ListView mListView;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.listeditor);
mListView = FindViewById<ListView>(Resource.Id.listView);
mItems = new List<string>();
mItems.Add("Milch");
mItems.Add("Brot");
mItems.Add("Apfel");
MyListViewAdapter adapter = new MyListViewAdapter(this, mItems);
mListView.Adapter = adapter;}
also I dont know the diffrents between AppCompatActivity and a normal activity. So general the user should see when he clicks on the button the new view (createlist) with my list.
I hadn't used anonymous delegates on Xamarin before, that's a cool thing. Try using an intent and passing the Context:
btnentrar.Click += delegate
{
StartActivity(new Intent(this, typeof(listeditorclass)));
};
Related
I am creating a responsive web app using vaadin 23.1.0 and got a problem that the double click event is not fired on an Iphone with Safari. Never had any issues with that on other platforms.
The following code illustrates the problem. Button click works on IOS, doubleclick doesn't.
#PageTitle("IosTestView")
#Route(value = "IosTestView", layout = MainLayout.class)
#PermitAll
#Log4j2
public class IosTestView extends VerticalLayout {
public IosTestView() {
H2 h2 = new H2("IOS Test View");
add(h2);
List<String> testData = Arrays.asList("One", "Two", "Three", "Four", "Five");
Grid<String> testGrid = new Grid<>();
testGrid.addColumn(new ComponentRenderer<>(a -> new Button("Go", b -> show(a))));
testGrid.addColumn(a -> a);
testGrid.addItemDoubleClickListener(a -> show(a.getItem()));
testGrid.setItems(testData);
add(testGrid);
}
private void show(String msg) {
Notification notification = new Notification();
notification.setPosition(Notification.Position.MIDDLE);
notification.setText("Item : " + msg);
notification.setDuration(5000);
notification.open();
}
}
No idea if there is an easy fix for this... but adding an extra button instead of using double click is not my favorite option...
Context Menu does work on IOS but I have no possibility to get the selected item - it's always null... seems to be the same issue...
Any help really welcome :-)
Regards
Stefan
Sounds like the same root cause as the other issue you described. The other issue was fixed in 23.1.1 - https://github.com/vaadin/flow-components/issues/3296.
Please update to the current version to see if this fixes your problem as well.
I created a thread (via a lambda expression) to fetch some data based on user input fields but when I try to click on dropdown menus while it is retrieving data I get the mini progress bar indicator. So is a new thread even being created? What am I doing wrong here?
Button doComputation = new Button("Get Results);
doComputation.addClickListener(event -> {
UI ui = UI.getCurrent();
new Thread(() -> {
// Do some work
ui.access(() -> layout.add(results);
}).start();
});
UPDATE: RESOLVED! Unneccesary ui.access calls were made, which locked up resources. Thank you to all that commented and helped.
The code looks correct to me (apart from the missing end parenthesis after ui.access). Is that the only ui.access call, and is that all you do inside it?
I made this example for reference, and the combo box stays responsive while the background task is running.
#Route
public class ThreadView extends VerticalLayout {
public ThreadView() {
Button runThreadButton = new Button("Start thread", e -> {
UI ui = UI.getCurrent();
new Thread(() -> {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
ui.access(() -> Notification.show("Completed"));
}).start();
});
ComboBox<String> comboBox = new ComboBox<>("Items", "One", "Two", "Three");
add(runThreadButton, comboBox);
}
}
So is a new thread even being created?
You can verify that by adding a System.out.println("Thread started") and checking whether that message is printed, or by running your application in debug mode and setting a breakpoint on the part that you're interested in.
What am I doing wrong here?
The code that you showed looks fine. I would guess there's a problem outside the shown code, namely that you have forgotten that you also need to add the #Push annotation. Without that annotation, the server will have no way of directly sending messages to the client.
I have a simple ActionBar with 3 tabs attached. When a tab is clicked, the fragment is inflated and the view shows. The tab being click event is fired using an event. Initially, the first fragment is inflated, but the others respond and inflate if clicked.
If I change the event being fired to an ICommand, only the last fragment is inflated and then if I click on the first tab, that and the last are inflated. Never the second.
My code is this
ICommand TabClicked
{
get
{
return new RelayCommand(() =>
{
tab.TabSelected += (object sender, ActionBar.TabEventArgs e) => TabOnTabSelected(sender, e);
});
}
}
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
fragments.Add(new TODFragment());
fragments.Add(new ConditionsFragment());
fragments.Add(new ResultsFragment());
AddTabToActionBar("Time", Resource.Drawable.crucifix_colour);
AddTabToActionBar("Conditions", Resource.Drawable.weather_colour);
AddTabToActionBar("Results", Resource.Drawable.tod_colour);
}
void AddTabToActionBar(string text, int iconResourceId)
{
tab = ActionBar.NewTab().SetTag(text).SetText(text).SetIcon(iconResourceId);
/* uncomment and comment out one of the two below to see the difference in operation */
tab.TabSelected += TabOnTabSelected;
//tab.SetCommand<ActionBar.TabEventArgs>("TabSelected", TabClicked);
ActionBar.AddTab(tab);
}
void TabOnTabSelected(object sender, ActionBar.TabEventArgs tabEventArgs)
{
var tabNo = sender as ActionBar.Tab;
var frag = fragments[tabNo.Position];
tabEventArgs.FragmentTransaction.Replace(Resource.Id.frameLayout1, frag);
}
Am I missing something fundamental here in the difference between ICommands and Events or is it something else?
I'm using Xam.Android and MVVMLight
I found the answer. When I create the partial class I define the UI objects like this (or something like this at least)
EditText myEditText;
EditText MyEditText = myEditText ?? (view.FindViewById<EditText>(Resources.Id.myEdit);
This is fine, but it does mean that once defined, it doesn't get redefined.
Not a problem if the UI is not really going to change, but every time an action tab is pressed, the fragment is refreshed. Only problem is the Id isn't changing as myEditText is not null.
The answer is add a method in the UI definition code that nulls the objects then in the main code, when the UI disappears, call the nulling method. Everything works then
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
I am newbie to Xamarin.Forms and stuck with a situation where I want to open up a popup box with my control details [e.g. View Employee Details] on click of parent page.
How can I open custom dialog box / popup using Xamarin.Forms?
Any example code will be appreciated?
Thanks in advance!
If you still want to have your popup's code in its own Page you can set up some custom renderers along the following logic.
1. A ModalPage & corresponding renderer
public class ModalPage : ContentPage { }
public class ModalPageRenderer : PageRenderer {
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
this.View.BackgroundColor = UIColor.Clear;
this.ModalPresentationStyle = UIModalPresentationStyle.OverCurrentContext;
}
public override void ViewDidLayoutSubviews()
{
base.ViewDidLayoutSubviews();
SetElementSize (new Size (View.Bounds.Width, View.Bounds.Height));
}
}
2. HostPage
public class ModalHostPage : ContentPage, IModalHost
{
#region IModalHost implementation
public Task DisplayPageModal(Page page)
{
var displayEvent = DisplayPageModalRequested;
Task completion = null;
if (displayEvent != null)
{
var eventArgs = new DisplayPageModalRequestedEventArgs(page);
displayEvent(this, eventArgs);
completion = eventArgs.DisplayingPageTask;
}
// If there is no task, just create a new completed one
return completion ?? Task.FromResult<object>(null);
}
#endregion
public event EventHandler<DisplayPageModalRequestedEventArgs> DisplayPageModalRequested;
public sealed class DisplayPageModalRequestedEventArgs : EventArgs
{
public Task DisplayingPageTask { get; set;}
public Page PageToDisplay { get; }
public DisplayPageModalRequestedEventArgs(Page modalPage)
{
PageToDisplay = modalPage;
}
}
}
3. HostPage renderer
public class ModalHostPageRenderer: PageRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
if(e.OldElement as ModalHostPage != null)
{
var hostPage = (ModalHostPage)e.OldElement;
hostPage.DisplayPageModalRequested -= OnDisplayPageModalRequested;
}
if (e.NewElement as ModalHostPage != null)
{
var hostPage = (ModalHostPage)e.NewElement;
hostPage.DisplayPageModalRequested += OnDisplayPageModalRequested;
}
}
void OnDisplayPageModalRequested(object sender, ModalHostPage.DisplayPageModalRequestedEventArgs e)
{
e.PageToDisplay.Parent = this.Element;
var renderer = RendererFactory.GetRenderer (e.PageToDisplay);
e.DisplayingPageTask = this.PresentViewControllerAsync(renderer.ViewController, true);
}
}
Then it is as simple as calling
await ModalHost.DisplayPageModal(new PopUpPage());
from your host page or in this particular case from the ViewModel behind.
What Pete said about PushModalAsync / PopModalAsync still remains valid for this solution too (which in my opinion is not a disadvantage), but your popup would appear with transparent background.
The main advantage of this approach, in my opinion, is that you can have your popup XAML/code definition separate from the host page and reuse it on any other page where you wish to show that popup.
The general purpose of what you are trying to achieve can be accomplished by using the PushModalAsync and PopModalAsync methods of Xamarin.Forms Navigation object.
The chances are that this is good enough for what you are needing - However - this isn't truely modal. I will explain after a small code snippet:-
StackLayout objStackLayout = new StackLayout()
{
};
//
Button cmdButton_LaunchModalPage = new Button();
cmdButton_LaunchModalPage.Text = "Launch Modal Window";
objStackLayout.Children.Add(cmdButton_LaunchModalPage);
//
cmdButton_LaunchModalPage.Clicked += (async (o2, e2) =>
{
ContentPage objModalPage = new ContentPage();
objModalPage.Content = await CreatePageContent_Page2();
//
await Navigation.PushModalAsync(objModalPage);
//
// Code will get executed immediately here before the page is dismissed above.
});
//
return objStackLayout;
private async Task<StackLayout> CreatePageContent_Page2()
{
StackLayout objStackLayout = new StackLayout()
{
};
//
Button cmdButton_CloseModalPage = new Button();
cmdButton_CloseModalPage.Text = "Close";
objStackLayout.Children.Add(cmdButton_CloseModalPage);
//
cmdButton_CloseModalPage.Clicked += ((o2, e2) =>
{
this.Navigation.PopModalAsync();
});
//
return objStackLayout;
}
The problem with the above is that the
await Navigation.PushModalAsync(objModalPage);
will immediately return after the animation.
Although you can't interact with the previous page, as we are displaying a new NavigationPage with a Close button shown - the parent Navigation Page is still executing behind the scenes in parallel.
So if you had any timers or anything executing these still would get called unless you stopped those.
You could also use the TaskCompletionSource approach as outlined in the following post also How can I await modal form dismissal using Xamarin.Forms?.
Note - that although you can now await the 2nd page displaying and then when that page is dismissed allowing code execution to continue on the next line - this is still not truely a modal form. Again timers or anything executing still will get called on the parent page.
Update 1:-
To have the content appear over the top of existing content then simply include it on the current page, however make this section of content invisible until you need it.
If you use an outer container such like a Grid that supports multiple child controls in the same cell, then you will be able to achieve what you want.
You will also want to use something like a filled Box with transparency that will cover the entire page also, to control the visible, see through section, that surrounds your inner content section.
I followed above approach and found it impossible to run on iOS 7.
I found this library BTProgressHUD which you can modify and use.
I Use its methods by Dependency service.
Actual library for popups.
https://github.com/nicwise/BTProgressHUD
Following example uses BTProgressHUD library internally.
https://github.com/xximjasonxx/ScorePredictForms