fragmentManager.beginTransaction().replace(R.id.fragment_container_view,mapFragment).commit();
As we know that, this way we can load or replace Fragment
But
In this snippet we are passing fragment container id.
Is there any way
to load fragment without passing ID or pass FragmentContainerView instead of id
you can use navigation graph action to navigate between fragments with one line of code like that :
Navigation.findNavController(this).navigate(R.id.action_fragment1_to_fragment2)
provided that :
you have a navigation graph that looks like this
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/nav_graph"
app:startDestination="#id/fragment_1">
<fragment
android:id="#+id/fragment_1"
android:name="Your.Package.Fragment_1"
tools:layout="#layout/fragment_1_layout">
<action
android:id="#+id/action_fragment1_to_fragment2"
app:destination="#id/fragment_2" />
</fragment>
<fragment
android:id="#+id/fragment_2"
android:name="Your.Package.Fragment_2"
tools:layout="#layout/fragment_2_layout">
</fragment>
</navigation>
and you've written the correct code to setup your activity with navigation components.
If you don't know what is navigation components I highly recommend taking the navigation lab on android developers where it should instruct you how to setup your project with it.
Learn Jetpack Navigation | Android Developers (Java)
for more information about navigation components and fragments follow these links and start reading Android Developers Tutorials.
Fragments| Android Developers
Navigation Components | Android Developers
Related
I'm using android Navigations for handeling my backstack.
I want to create a transition from the fragment data to fragment map.
Right now I have the problem, when I execute a Navigation Event from a button in my app like this:
NavController navController = Navigation.findNavController(view);
navController.navigate(LoadDataFragmentDirections.actionDataToMap());
I get navigated to my destination map. But I can't click data in my navigation menu anymore.
If I backpress, my view goes back to data like intended.
An then, the button data get's also clickable in the menu again.
Here is my navigation graph.
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/mobile_navigation"
app:startDestination="#id/navigation_load_data">
<fragment
android:id="#+id/navigation_load_data"
android:name="com.example.axistracker.ui.app.open_data.LoadDataFragment"
android:label="#string/open_file"
tools:layout="#layout/fragment_load_data">
<action
app:launchSingleTop="true"
app:popUpToInclusive="true"
android:id="#+id/action_data_to_map"
app:destination="#id/navigation_map" />
</fragment>
<fragment
android:id="#+id/navigation_map"
android:name="com.example.axistracker.ui.app.map.MapFragment"
android:label="#string/map"
tools:layout="#layout/fragment_map" />
</navigation>
It feels like, I don't replicate the same behaviour with "navController.navigate(...)" as if I would just click in my menu.
I'm using:
implementation 'androidx.navigation:navigation-fragment:2.5.0'
implementation 'androidx.navigation:navigation-ui:2.5.0'
I'm happy about any ideas!
PatPat
I’m having a hard time figuring out why my App Widget ListView won’t populate with data. Everything seems to be wired up right. When I debug, I can see the data that is being retrieved from my database (Firestore). However, it still won’t populate into the App Widget.
I created a new Issue on my Github to make it easier to view the problem:Github Issue
RemoteViewsFactory
The data is successfully retrieved from Firestore DB
List<Review> reviews is populated
The Review objects within it contain the right data
get() methods return the right data
ReviewsAppWidgetProvider
ReviewsWidgetService Intent is created
setRemoteAdapter() is called using the Intent and passing in the ListView as well
updateAppWidget() is called
notifyAppWIdgetViewDataChaged() is called
ReviewFragment
ReviewsAppWidgetProvider.updateAppWidgets() is called when adding or deleting reviews
AndroidManifest
ReviewsAppWidgetProvider declared as a reveiver
Intent Filter set for action.APPWIDGET_UPDATE
ReviewsWidgetService declared as Service
permssion BIND_REMOTEVIEWS set
As you said, everything is ok with fetching data. But it's still draw a loading view. So the problem is in your divider. View can't be used in app widgets, because launcher process doesn't know about view, it's only know about limited count of views, all views that can be used, you can find here.
So how to make a such divider?
Firstly you need a shape, so it will be something like bottom_border.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="0.5dp"
android:color="#CCCCCC" />
</shape>
So now in your root view add background bottom_border.xml like:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:background="#drawable/bottom_border"
android:layout_width="match_parent"
android:layout_height="wrap_content">
...
I'm trying to add a Navigation Menu to an existing project in Android Studio. However, while following the instructions on the official website, I added a <android.support.v4.widget.DrawerLayout ... tag around the rest of my view, and under the main ConstraintLayout that has the main activity layout, I put the sample Navigation Draw underneath that:
<android.support.design.widget.NavigationView
android:id="#+id/navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="#menu/my_navigation_items" />
The last line causes some problems though when building:
Error:error: attribute 'com. ... :menu' not found.
I can't figure out why this is happening. The app part of app:menu is defined in the DrawerLayout tag as: xmlns:app="http://schemas.android.com/apk/res-auto"
This seems to also have the effect of giving me the error Cannot resolve symbol R in my MainActivity.java file.
Anyway, any help is very much appreciated!
Do you have the compile 'com.android.support:design:27.0.2' in your build.gradle file?
If not, try to add it.
I need my widget to interact with any built-int browser. What I mean by an interaction is to know the content of the visible web page. Is it possible for a floating widget to "know" what DOM element lies below and read some info about the element? The following scenario is demanded: user moves the widget across a browser with some HTML page visible, the widget then recognizes HTML elements and shows the user some information about that element.
If there is no such possibility, is it possible to read the whole text from the actual web page? Only text, without any other objects.
if you want to show a web page directly on your app, you can use android webview. Make a activity with a webview.
webveiw.xml
<?xml version="1.0" encoding="utf-8"?>
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
then you can use in the activity
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
you have to add this part in your manfiest file
<manifest ... >
<uses-permission android:name="android.permission.INTERNET" />
...
</manifest>
Use this guide
http://developer.android.com/guide/webapps/webview.html
I want to use an activity as a dialog in my android application. Till now, I've used AlertDialogs but I want to make my app more fancy. I've done a lot of research on this but couldn't find a satisfactory answer.
I created a new activity named DialogActivity.java and dialogactivty for the java and xml files respectively.
So, How do I call this activity as a dialog in some other activity?
AND
How do I give this activity a round cornered rectangle dialog shape?
Thanks in advance!
You can set a dialog theme to activity as
<activity android:theme="#android:style/Theme.Dialog" />
and use
<activity android:theme="#android:style/Theme.Holo.Dialog" /> // api level 11 and above
in manifest for the activity required.
You need to start the activity using startActivity(intent)
From the official documentation,
If you want a custom dialog, you can instead display an Activity as a
dialog instead of using the Dialog APIs. Simply create an activity and
set its theme to Theme.Holo.Dialog in the manifest element:
<activity android:theme="#android:style/Theme.Holo.Dialog" >
That's it. The activity now displays in a dialog window instead of
fullscreen.
Use Theme.Dialog for API 10 or lower.
try this :
android:theme="#android:style/Theme.Dialog">
entry in manifest for the activity you required.
#ChinmayDabke To display with rounded corners, you need to create a new shape using xml and set it as the background drawable.. be sure to also set transparency for your activity. For more detailed information on this, there are many up-to-date topics available - I just wanted to give a quick answer to this old post, since you had asked!
My mistake - you don't need to set as Transparent - I meant to say set no Titlebar!
Example:
Create a Shape for the rounded background, inside your res/drawable folder:
shape_background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid
android:color="#color/colorOfActivityHere"/>
<corners
android:radius="12dp" />
<padding
android:left="10dp"
android:top="10dp"
android:right="10dp"
android:bottom="10dp" />
</shape>
Then set the shape as the Background of your activity's parent layout:
layout_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/layout_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="6dp"
android:background="#drawable/shape_background"
android:orientation="vertical">
...
</LinearLayout>
And in your Activity.java, set no titlebar:
Activity.java
requestWindowFeature(Window.FEATURE_NO_TITLE);