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">
...
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
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
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);
I have a normal autocomplete:
<AutoCompleteTextView
android:id="#+id/autocomplete_names"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/namesauto_prompt"
android:imeOptions="actionDone"
android:completionThreshold="2"/>
...
AutoCompleteTextView nameinp = (AutoCompleteTextView) findViewById(R.id.autocomplete_names);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, names);
nameinp.setAdapter(adapter);
I won't bother showing the names list, because it which works fine on my tablet running ICS, both in landscape and portrait modes. In landscape on my phone (Gingerbread) it does OK - the names appear the same way that autosuggest for texting does. But in portrait mode it just renders a blank listview beneath the autocomplete input. Any ideas why?
UPDATE
So, having played around with it, I notice that my list is there, it's just that it's white text on a white background (kind of hard to read). I can set my
android:popupBackground
to whatever color I like (dark gray is a contender at the moment) but I can't see a way to change the text color for the popup (or dropdown as it were), nor do I really understand why it's white in the first place...
I don't know the problem of this issue, because even I faced this issue with AutoCompleteTextView. I found a workaround for this.
What you can do is set a custom xml in the ArrayAdapter that will have the TextView color set to black.
The custom TextView file my_custom_textview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/text1"
style="?android:attr/dropDownItemStyle"
android:textAppearance="?android:attr/textAppearanceLargePopupMenu"
android:singleLine="true"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:ellipsize="marquee" />
And set this xml in your ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.my_custom_textview, names);
nameinp.setAdapter(adapter);
Hope this helps you..
I'm trying to do something similar to iOS editable UITableView. I have a list of "added items" if the user clicks on "Add new item" he is taken to a PreferenceScreen with multiple <Preference> elements, onclick the should disappear from this screen and add it to the "Added list" (actually a <PreferenceCategory>), then they should be able to remove them from here or edit their order. This is similar to iOS editable lists.
This is my XML:
<PreferenceScreen android:title="ALL APPS" android:key="app_list">
<!-- A <preference> for each app -->
</PreferenceScreen>
<PreferenceCategory android:title="ADDED APPS" android:key="my_apps_list">
</PreferenceCategory>
I have tried uncountable times and I cannot get it to work.
How can I get it done?
I've experimented around a bit and it's actually very easy when you nest your PreferenceScreens.
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<CheckBoxPreference android:title="Check it!" />
<PreferenceScreen android:title="To the other preferences!" android:summary="I really hope this works <3" >
<EditTextPreference android:title="Edit your name" android:summary="Edit your name :)" />
<CheckBoxPreference android:title="Accept answer" />
</PreferenceScreen>
</PreferenceScreen>
PS: Please excuse my hard-coded string literals - it was just for testing! :)
this looks like a very similar question to what i've asked in the past:
android - showing listView in PreferenceActivity
when selecting the items to show , store them in some way (DB ,references ,etc...) and then use the solution i've found .
as you can see , the view used in preference activity is actually a listView , so it's weird to put a listView in a listView . what you need is a special trick , and that's something i've written about .
Please have a look to the accepted answer on this question:
How to remove Android preferences from the screen
Sometimes, if categories are present, you have to
"reference the category containing the preference you wanted to remove and then remove that preference from that category"
like the answer there says. Isn't this also your case?
Hope this helped.