how to make action from included graph? - android-navigation

I can make action from nested graph to any destination, but apprently I can't make action from included other file.
i thought included graph and nested graph is almost same.
how can I make action from included graph?

You can create a global action in the main navigation graph
Like:
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_graph"
app:startDestination="#id/x">
<fragment
android:id="#+id/x"
android:name="x"/>
<include app:graph="#navigation/x" />
<fragment
android:id="#+id/firstFragment"
android:name="x"/>
<action
android:id="#+id/action_global_to_firstFragment"
app:destination="#id/firstFragment" />
</navigation>
And then call it with the id:
navController.navigate(R.id.action_global_to_firstFragment)
The navController must be the defined in the ActivityContainer, if it generate a destination error, maybe you aren't using the main navController

Related

AccessibilityTraversalBefore doesn't work with talkback

I have a recycler view with a list of items. This is how it looks:
I need to add Talkback support. The problem is with the order of focusing inside recycler item view.
This should the correct order:
1. Name of first member (A)
2. Amount under first member's name (2469...)
3. Name of second member (B)
4. Amount under second member's name (2469...)
The problem is that default focus order is different:
1) Name of the first member
2) Name of the second member
3) Amount under the first member
4) Amount under the second member
The solution should be pretty easy. There is a parameter android:accessibilityTraversalBefore="#+id/someID" which change the order of focus. I use this parameter in other views in my app without a problem - it works nice. However when I use it here it doesn't have any effect at all - the views are still focused in the default order.
Let's take a look at recycler item layout:
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="56dp">
<android.support.constraint.Guideline
android:id="#+id/vGuideline"
style="#style/Layout.Guideline"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.5"/>
<android.support.v7.widget.AppCompatImageView
android:id="#+id/vFirstAvatar"
style="#style/Image.AvatarMember"
app:layout_constraintBottom_toBottomOf="parent"
tools:src="#drawable/avatar_multiple" />
<!-- Ellipsized because it can overlay the second member. -->
<android.support.v7.widget.AppCompatTextView
android:id="#+id/vFirstName"
style="#style/TextView.NameEllipsized"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="8dp"
android:importantForAccessibility="yes"
android:layout_marginRight="8dp"
android:accessibilityTraversalBefore="#+id/vFirstAmount"
android:textAppearance="#style/ListPrimaryTiny"
app:layout_constraintLeft_toRightOf="#+id/vFirstAvatar"
app:layout_constraintRight_toLeftOf="#+id/vGuideline"
app:layout_constraintTop_toTopOf="parent"
tools:text="Suzan" />
<!-- Ellipsized because it can overlay the second member. -->
<android.support.v7.widget.AppCompatTextView
android:id="#+id/vFirstAmount"
style="#style/TextView.NameEllipsized"
android:layout_marginTop="2dp"
android:accessibilityTraversalBefore="#+id/vSecondName"
android:textAppearance="#style/ListSecondary"
android:importantForAccessibility="yes"
app:layout_constraintLeft_toLeftOf="#+id/vFirstName"
app:layout_constraintRight_toRightOf="#id/vGuideline"
app:layout_constraintTop_toBottomOf="#+id/vFirstName"
tools:text="$22" />
<android.support.v7.widget.AppCompatImageView
android:id="#+id/vSecondAvatar"
style="#style/Image.Avatar"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:src="#drawable/avatar_multiple" />
<!-- Ellipsized because it can overlay first member. -->
<android.support.v7.widget.AppCompatTextView
android:id="#+id/vSecondName"
style="#style/TextView.NameEllipsized"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:importantForAccessibility="yes"
android:accessibilityTraversalBefore="#+id/vSecondAmount"
android:layout_marginTop="11dp"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="end"
android:textAppearance="#style/ListPrimaryTiny"
app:layout_constraintLeft_toLeftOf="#+id/vGuideline"
app:layout_constraintRight_toLeftOf="#+id/vSecondAvatar"
app:layout_constraintTop_toTopOf="parent"
tools:text="Dave" />
<!-- Ellipsized because it can overlay the first member. -->
<android.support.v7.widget.AppCompatTextView
android:id="#+id/vSecondAmount"
style="#style/TextView.NameEllipsized"
android:layout_marginTop="2dp"
android:importantForAccessibility="yes"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:gravity="end"
android:textAppearance="#style/ListSecondary"
app:layout_constraintRight_toRightOf="#+id/vSecondName"
app:layout_constraintLeft_toLeftOf="#id/vGuideline"
app:layout_constraintTop_toBottomOf="#+id/vSecondName"
tools:text="$8" />
</android.support.constraint.ConstraintLayout>
Do you have any idea what is the reason why Talkback completely ignores
AccessibilityTraversalBefore attribute?
If you look at the OrderedTraversalController in the "TalkBack" project, you can see that TalkBack does in fact respect this property. I appologize, but I don't have time to set up a test for this and confirm, but my guess would be that setting this up in XML isn't going to work. It is likely that the recycler view is overriding the XML property at run time.
Try doing it in code after all the views have rendered. Probably a few race conditions involved as well! I don't actually know what callback you would have to use to get this to happen reliably. I may investigate more later.

i cant add button to linear layout

I have a listActivity that displays via an adapter an xml feed fetched from the web, adn the layout file activity_list_feed.xml :
`<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>`
In the graphic editor i cannot drag a button into this layout, and when i try to hardcode as per this file :
`<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/addBtn"
android:text="Add New Item"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="addItems"/>
<ListView
android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"
android:transcriptMode="normal"
/>
</LinearLayout>`
i get a compile error message :
java.lang.ClassCastException: android.widget.LinearLayout cannot be cast to android.widget.TextView
How can i add a button on top of the list because i want to refresh the pull.thank you.
The code that you provided actually works in its current state in Android Studio:
Make sure that in your java code, you are referencing the correct item. Make sure that you're setting the overall layout to be that layout, and THEN doing findViewById(R.layout.addBtn).
Also, try changing the Android Version in your IDE to 22 (as I have it set in the top right corner of the picture). That may solve your error.
I managed to add the button in the editor and this without setting to API 22 as per your picture. However the program didn't compile still.
The message error "ArrayAdapter requires the resource ID to be a TextView" meant i didn't provide the right argument to the adapter.
According to this answer :
"ArrayAdapter requires the resource ID to be a TextView" xml problems
it appears that the choice of the constructor is important, since i wanted to add a button in the view, i must use the constructor with 4 arguments (the additional argument being the id of the view):
http://developer.android.com/reference/android/widget/ArrayAdapter.html#ArrayAdapter(android.content.Context,int,int,java.util.List)
Using this constructor solved the problem.

android, xmlns, No resource indentifier error

In an xml layout file, the xmlns is already defined, but I get this error at compile time: No resource identifier found for attribute. Why is that? thanks
I'm following a Facebook dev tutorial on facebook site https://developers.facebook.com/docs/getting-started/facebook-sdk-for-android/3.0/ the layout file is as follows:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<com.facebook.widget.ProfilePictureView
android:id="#+id/profilepic"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
app:preset_size="large" app:is_cropped="true"
/>
</ScrollView>
I figured it out, have to replace /res-auto with res/com.facebook.samples.profilepicture
Your layout file looks correct. check that in your 'project.properties' file, the 'android.library.reference.1' value points to the correct location.
The res-auto is feature properly supported in API level 17. It must be applied for all layouts using custom attributes. It is automatically replaced on build time, by eclipse.
Ref Updated SDK Tools and ADT revision 17

Android: define which attributes a custom view uses for content assist

I've got some custom views and custom defined attributes. I'd like to define which attributes my views use so that eclipse can use that for content-assist.
For example, I've got a custom xml attribute declared like so in my res/values folder:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TagAttrs">
<attr name="spColor" format="color" />
</declare-styleable>
</resources>
And my layout file uses a custom view with the custom attribute:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.twp"
...
>
<com.twp.TestView
android:id="#+id/testView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:spColor="#FF00FF" >
...
</com.twp.TestView>
</LinearLayout>
If I use the android: prefix, eclipse presents all the options it would for a LinearLayout (from which TestView derives), but if I use the app: prefix, it shows in red at the bottom that "Element com.twp.TestView not available". Also, if I try content-assist inside of spColor, it says "Content Assist not available at the current location." I would think since I defined the "app" namespace, it would be able to find my stylable declaration and at least know that spColor is a color.
So it this just a limitation of eclipse, or can I explicitly define a view's custom attributes?
I believe the value for the name attribute in declare-styleable needs to match the unqualified name of the associated class or the unqualified name of a superclass of the associated class. So if the direct superclass of TestView is LinearLayout, then the value of the name attribute in the associated declare-styleable should be TestView, not TagAttrs.

How to use a ShapeDrawable with an xml layout resource

I would like to be able to define a ShapeDrawable in my layout file and then inflate that so I can draw on it.
I have followed the tutorial on the android developers' site but I cannot see how I reference my ShapeDrawable in my main class file.
How do I actually inflate it?
I have put the following the following into my layout file:
<com.example.shapedrawable.CustomDrawableView
android:id="#+id/customDrawableView"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
Once you have defined the ShapeDrawable in its own XML file, you need to add the following to the layout.xml where you want it to be included:
<ImageView
android:src="#drawable/shapeDrawable_filename"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
If you want to do it programmatically, I don't have an answer (yet), but from your question, it seems this should work!
Let me know if that helps ;)

Resources