Hi everyone I am using eclipse to develop an android app. I have three layouts, namely a main layout and two other layouts linked to the main layout. I have created .xml and .java files for all the pages. My application runs and I can move between my main layout and one of the layouts but when I try to access the other layout the screen just blinks and nothing else happens. I am using bluestacks to test the app. below is the code for the button that is supposed to execute and move between the layouts. Show_Meds.class is the problematic one. What am I doing wrong?
`Button butEnter = (Button)findViewById(R.id.btnEnter);
butEnter.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if ( rEnterMed.isChecked()){
startActivity(new Intent(MainActivity.this, Enter_Meds.class));
}
else if (rShowMed.isChecked()){
startActivity(new Intent (MainActivity.this, Show_Meds.class));
}
}//end of onClick
});`
I do not have an answer for you yet, But please verify these points to find out whats going wrong.
Also, if you are unable to produce favourable results, please post the codes for all your layout.xml files, your manifest files and your Activity.java files.
1- Make sure you have registered your Activities Enter_Meds and Show_Meds to your manifest files.
2- Try replacing the layouts xml file of MainActivity to Enter_Meds and Show_Meds one by one in setContentView. This way, you'll know if the xml view are actually working OK.
3- Inside onClick method, print out the value of v.getId() to verify if the view has been clicked correctly.
Related
I made an application where I integrated the tabbed activity. In the tabbed activity I put 3 fragments. Now in the 3rd fragment I put a button and I want when I click on the button it redirects me to a new activity I did. I used an intent as we usually do between activities but it doesn't work. Need help please
use getContext instade of Activity.this. use the below code in your button to redirect from fragment to activity
yourButton.setOnClickListener(view -> {
startActivity(new Intent(getContext(), Your_Activity.class));
});
If the problem is not solved yet, let me know with logcat error.
I'm using android studio 4.1.1 and kotlin.
I'm trying to learn programming Android apps using Android Studio and Kotlin. I have a question that a couple of tutorials and searching threads have not answered for me. How does control pass from the MainActivity.kt class to another class, i.e: FirstFragment.kt?
I'm doing fine with other things I'm learning in tutorials, but I cannot figure this out.
Example:
I create a new Basic Activity app in Android Studio with Kotlin. In the java directory, I see these classes: FirstFragment.kt, MainActivity.kt and SecondFragment.kt.
In the res/layout/ directory, I see: activity_main.xml, content_main.xml, fragment_first.xml and fragment_second.xml.
Question 1) When the app loads in an emulator, I see the button and textView from the fragment_first.xml. How does this happen? I cannot see in the code where it says, "load fragment_first.xml".
MainActivity.kt has setContentView(R.layout.activity_main) which loads that layout. activity_main.xml has <include layout="#layout/content_main" />. But from there, I do not know where to find the code that loads the fragment_first.xml layout.
I believe that when fragment_first.xml loads, control passes from MainActivity.kt to FirstFragment.kt, yes? Question 2). Is this because of the onCreate function?
Thanks for helping me to understand this better.
There are multiple ways to load a fragment. Traditionally, you use the FragmentManager to create a Fragment transaction that tells the Activity to place a Fragment into the view hierarchy and start managing its lifecycle.
More recently, they have added the Navigation component, which can be used in place of directly using the FragmentManager.
In the current new project Basic Activity, the layout activity_main.xml includes the layout content_main. In content_main.xml, you'll see that it includes a fragment element that is set to the Fragment (using the name parameter) NavHostFragment, which is a special Fragment that the Navigation component uses to host children fragments that are specified in a navigation XML file. This fragment element also specifies the navigation xml file using the navGraph property. It specifies nav_graph.xml, which you'll find in the res/navigation directory.
If you open nav_graph.xml, you'll see that it has FirstFragment set as the home fragment, so that is what pulls it up as the first fragment that you see.
Basically, the control flow is:
Activity's onCreate() sets content view to activity_main, which includes content_main.
content_main includes a NavHostFragment that is automatically inserted in the view hierarchy so the Activity starts running it.
The NavHostFragment is set in the XML to use nav_graph, which tells it to load FirstFragment first.
My program is fullscreen application. On start I use some checks and if something is wrong, error dialog is shown. I need two windows (main fullscreen, and dialog) were here and all graphics were ok.
When I use this code:
primaryStage.show();
/*..some checks*/
dialogStage.show();
.. there is no fullscreen. It's somehow overlapped by other windows.
This one works better:
stage.setOnShown( new EventHandler<WindowEvent>() {
public void handle(WindowEvent windowEvent) {
/*..some checks*/
dialogStage.show();
}
});
primaryStage.show();
But... I can see task panel from Windows. It becomes hidden when dialog is closed.
And also I can see default java icon there. Although I've set custom icon before.
Looks like setOnShown() is called before all graphical updates are done.
Is there any event or something to know it?
I also tried Timeline from animation to call a small delay. But without success.
The same with calling dialog from additional thread (with Platform.runLater() of course :) ). This way fullscreen hides at all.
Maybe on JavaFX8 things are better?
I have a really weird issue with Ektron. A while back, I created a widget called NehgsTooltip. It worked fine. I later created another widget called NehgsLogin. Now, when I try to add NehgsTooltip to a page, the widget that appears on the page is called NehgsLogin.
The widget in my header has the right name
but when it gets dropped on the page the name changes
When I try to edit the widget, when I click the "choose" button, choose menu doesn't open. I'm not sure if this is because NehgsLogin doesn't have any options. However, when I manually enter the needed content title and ID and save it, the widget works as it's supposed to.
I can't figure out if there is an error happening in Ektron, or if the NehgsTooltip has just been misnamed somewhere. I checked the .ascx and .cshtml files and nowhere in there is the widget being names "NehgsLogin" (the phrase doesn't exist in any of those documents). I also checked the widget in settings, and both Widget Title and Widget Label are set correctly. What would be causing the widget to load as NehgsLogin, and is it actually loading the wrong widget, or is it just giving it the wrong title?
The title of the widget that you see in the Pagebuilder toolbox comes from the widget settings in the workarea. The title that is displayed on the widget itself is usually set in code behind like this:
protected void Page_Init(object sender, EventArgs e)
{
...
_host = Ektron.Cms.Widget.WidgetHost.GetHost(this) as Ektron.Cms.PageBuilder.WidgetHost;
_host.Title = "Archive Widget";
...
}
So I would check those two locations to ensure they are correct.
I see you are using CSHTML, and in another SO question you mention MVC, please not Ektron is not an MVC application.
Getting started with xCode 4.6.3 and I'm running into a hiccup.
I've built a simple app using the UIWebView to display a local HTML file and it's contents. I used that to debug any issues with the HTML and/or image displays and I'm all set.
Now I need to recreate that within a larger project I've built with storyboards for all my navigations between multiple view controllers. My issue comes when I'm trying to control-click drag from the WebView into the ViewController.h code below the #interface like many tutorials show, and that worked fine within my smaller single view controller app. It won't do it. I know I'm missing something obvious here. Am I going to have the set up these screens (I have multiple ones to do this same way) as separate xib files and add them into my main project?
Thanks for any help and clarification.
-Chris
You can create a class called for example myWebViewController and in Interface builder add a UIWebView to it. The control+drag to the header file will work.
Every time you want a UIViewController that has a browser in it, define its class as myWebViewController in Interface Builder.
Try not to repeat code. If you see UIViewControllers or any other UIView...that do the same thing, you can group them into a class that you use over and over.