"Fold-out" for row in RecyclerView - java

Java 8, min SDK: 24, target SDK: 27
My app displays a map with some type of map marker (within a Fragment) and if I click on one of these markers, a popup comes up to show some additional information about this marker. Currently I'm using a normal AlertDialog for that but I might replace it with a DialogFragment in the future.
Inside the dialog there's a RecyclerView that is filled with multiple values. If I click on one of the rows, I want my app to open a "fold-out" underneath it (the other rows should move down) that displays even more information about that row. Clicking on the row again should close that "fold-out".
Similar to what the FoldingCell library does but I want to add to the original row (instead of replacing it) and also don't need the fancy animation.
Like this:
Is "fold-out" the right word for it? I'm pretty sure I saw a similar question here on Stackoverflow (might have been for iOS) a while back but I've not been able to find it again yet. I know how to do the whole onClick thing for the map and the RecyclerView but how do I accomplish the "fold-out" part (create design in xml, then load via Java class)?

Related

Inline Clickable List Layout in Android

I want to create a sort of inline list of clickable text blocks in Android Studio. Below is the closest image I could find to the effect I would like. How would I achieve such an effect?
The information shown will be just a string, however clicking on this will take the user to another activity. It would be good if the text blocks also had a background, by the looks of it this app uses an image as the background, which should be fairly easy to set if the list is made from text views. I just don't know how to make a list with variable length inline objects.
See here: https://github.com/google/flexbox-layout
What I was looking for was specifically a horiztonal, wrapping, inline list.

Java selecting an option when clicking specific position within JScrollPane

I have developed a chat room application in Java that allows users to broadcast messages to every online user. I want to develop a new functionality that will allow the user to click on one of the online users in order to have a private chat with him/her. For this purpose I have developed a scroll-able text area that will contain those online users.
I think I could set the coordinates of each position that the name will be located at, in the text area so then when a mouse button is clicked I will compare this position against a position of the name in the string output of array list that was passed from the server (i.e. [Adrian, Buddy, Bob]).
As I have mentioned before, I am using a scroll-able text area for showing the online list, therefore I am not entirely sure if this approach would work out once I scroll down the list and click one of the positions.
Perhaps you could recommend me another approach I could adapt, or clarify if this one would work.
Here is the image of my chat client:
As I have mentioned before, I am using a scroll-able text area for
showing the online list, therefore I am not entirely sure if this
approach would work out once I scroll down the list and click one of
the positions.
Working with Scrollable TextArea for selecting items and responding with it the way you described: it will just be a hazard. Use JList with ListSelectionListener instead.
Tutorial Resource:
How to use List
How to Write a List Selection Listener

Android Testing: What do to when nothing has an id?

I'm trying to write some automation scripts for an app I have. I've done the tutorial on Robotium's site and have a basic understanding on how I can automation. However from what I can tell regarding the app I'm testing is by using the android hierarchy viewer I see that all of the views have no ids that were explicitly defined.
As you can see from the screen capture there are views upon nested views. The IDs for them read like 0x17e0 or 0x17de. How can I reference these, specifically, in a robotium script? The end result is I'm trying to get it to fire a click even on one of the Text Switcher views. So far I've only been able to make it work if I give it a pixel point to go to, or if I give it the text that appears in the button (but the text is dynamic and would make for a poor test).
Do I have to use the getCurrentViews() to filter down to the text switchers? Or do I have to figure out a way to traverse the entire tree going from FrameLayout>RelativeLayout>FrameLayout>LinearLayout>TextSwitcher ?
If I have to traverse the entire tree how do I get view upon view upon view?
While I couldn't get the ViewGroup() and getChildAt() methods to work for me I ended up doing something different:
// Grabbing all the LinearLayout views found under view with with id of 'content'
ArrayList<LinearLayout> linearLayouts = solo.getCurrentViews(LinearLayout.class, solo.getView(R.id.content));
// The 4th item in the linearLayouts list is the one I need
View pickerList = linearLayouts.get(3);
// Grabbing the buttons in the pickerList
ArrayList<TextSwitcher> buttons = solo.getCurrentViews(TextSwitcher.class,pickerList);
// Now I can click on the buttons
solo.clickOnView(buttons.get(0));
I will say this is slow. It takes about 10 seconds for the first button click to fire. But once it goes it flys.
I would vote to say you really probably want to get some IDs added somehwere in the hierarchy, it is a one line change that will make your life a hell of a lot easier.
But i am not without help if for some reason you cannot get this done, to do this you are going to have to walk the entire to get to the view you want.
Getting the top level view, you will be able to cast it into a ViewGroup. ViewGroups have a method called getChildAt() which you can then use to get a child at a given index, the index is 0 based and will match what you see in the hierarchy viewer so you can chain together theses commands to get to the view you want to interact with.
I have not used Robodtium very much, but i know that AndroidViewClient does exactly what you want. Here is a code snippet that dumps Id of the home view:
ViewClient(*ViewClient.connectToDeviceOrExit()).traverse(transform=ViewClient.TRAVERSE_CIT)
Here is the result dump:
com.android.launcher2.CellLayout id/cell3 None
com.android.launcher2.ShortcutAndWidgetContainer NO_ID None
com.android.launcher2.BubbleTextView NO_ID Email
com.android.launcher2.LauncherAppWidgetHostView NO_ID None
android.widget.AnalogClock id/0x7f0f0014 None
com.android.launcher2.BubbleTextView NO_ID Camera
com.android.launcher2.BubbleTextView NO_ID Settings
com.android.launcher2.BubbleTextView NO_ID Gallery
com.android.launcher2.LauncherAppWidgetHostView NO_ID None
android.widget.LinearLayout id/0x7f080167 None

Multi-page application with corresponding pictures and text

I'm new to Java and Android. I have been trying for the past week to make an app for my phone. The app consists of 4 pages, which are diagrammed below:
Page 1: Contains a picture taking up the size of the screen. If I click on the picture it needs to go to "page 2".
Page 2: Consists of an icon on the left (say the flag for instance) followed by a text field (eg. USA). When "USA" strip is clicked it needs to go to page 3.
Page 3: Consists of text, picture and then more text from a string. This page needs to correspond to the strip clicked on in page 2 ("USA" in this example). There are also two buttons at the bottom of "page 3" and "page 4" which when pressed need to go to the corresponding page numbers.
Page 4: This page is displayed if the "More" button is pressed on "page 3".
I would like this phone to work on a minimum Android 2.2 or 2.3. All logos, pictures and string texts need to be locally available (resources folder) and not website based. I have tried all sorts of combinations of ListView's and buttons with OnClickListener's as well as toast screens. My limited knowledge of programming is frustrating.
My question is if there is a template around which will help me out with this app? Or if there are any web resources.
In Android, individual "pages" or "screens" can be implemented as Activitys. You need to extend the Activity class and add the components that you wish to display. Most of the layout can be done in an XML file. I strongly suggest that you google for a tutorial that illustrates the basics of Android programming. From there, you can start by creating an app with two pages. And then just keep adding a little bit at a time until you get the complete app that you want.
There some easy ways to do this. If you want to be backwards compatible to SDK 8 you can do this in two ways. You can use Fragments or Activities for each layout. If you implement fragments, I suggest reading http://developer.android.com/guide/components/fragments.html inside there you will about using the FragmentActivity instead of the Activity. Read this link http://developer.android.com/tools/extras/support-library.html as it will have the needed libraries to implement the Fragments in older versions of the SDK. It does looks like you looking for some navigation buttons that reside on the bottom of the layout. In order to fully implement a layout that has this view on the bottom of the screen in SDK 8, you will need to create your own View and place it on the bottom of the screen. RelativeLayout and alignParentBottom = "true" will accomplish this. There is also a way to do this using a ViewPager which will also work in the backwards compatibility requirements you have. I am sorry the amount of information I am throwing at you but I really would recommend looking into other questions posted by users on this topic. How to navigate to another page in android? for example. Good luck and everything you are looking for is able to be learned through a Google search. Maybe not all at once.

SMS Balloons / Long Chat Boxes

I want to be able to add a text-messaging balloon every time the user revives data from a HttpGet, I want it so that it looks nearly identical to the default Android text messaging UI. I'm fine with all the code, I just need a way to create the UI and create another text balloon every time data comes back from a HttpGet request.
Thanks ever so much, for the answering this questions and I'm sure there's an easy way to do it, yet I've found no way by using the 'ole Google.
I am doing something similar for my app am doing the following to achieve it:
You will need a 9-Patch-Image (a stretchable PNG, see here) that represents the bubble. You want to make the part stretchable that does not include the corners of the bubble. You can create the bubbles using an image editor of your choice (I'd recommend a vector graphics editor like Inkscape). Then use the 9-Patch editor included in the Android Developer Tools to transform the PNG image into a 9-Patch PNG.
Create a custom layout file for one bubble. Create a textview inside it, and add your bubble as a background resource. (android:background)
Use an arraylist with a custom adapter to inflate and fill your items.
So far, this will give you identical bubbles as background for all messages.
If you want to get fancy, you can create different bubbles for participants, and use the setBackgroundResource method in your Adapter to set the correct background.
Further, if you wish to align them left or right, like in the message app, you will need to add spacers to the left and right of your TextView in the layout file. I used FrameLayouts with a fixed width. Make sure to set their visibility to GONE.
As with swapping the different bubble colors, just set the visibility of the left/right spacer.

Categories

Resources