Android Espresso perform click on first match - java

Is there a method firstMatch() in the Espresso library? Right now I am getting this exception
android.support.test.espresso.AmbiguousViewMatcherException matches multiple views in the hierarchy.
I have a RecyclerView and some of the items are displaying R.id.textRowBottom, but not all of it. I want to get the first match and perform a click on it.
It looks like this
onView(allOf(withId(R.id.textRowBottom), isDisplayed())).perform(click());

If you want to test items in a RecylerView you could use this:
android.support.test.espresso.contrib.RecyclerViewActions
So you can select an specific item in the list by its position, something like:
onView(withId(recyclerViewId)).perform(
RecyclerViewActions.actionOnItemAtPosition(0,
click(R.id.textRowBottom));

Related

Recyclerview in a recyclerview activity

using firebase-ui and some coding I have set up my code to work like this:
1) it retrieves data from firebase (image, text and so on), then it passes them to another activity.
2) the new activity receives datas like strings and shows them.
Just to give you an idea I am looking forward to building a streaming app. What I want to do is to show an episode list via recyclerview.
What I am doing right now is a nested scroll view and a copy-paste script to pass up to 26 episodes, but this is not a really good method and I would like to have some suggestions in order to go forward in the best way and solve this problem.
this is a screenshot of the app: https://imgur.com/a/vgBnZTA I am just passing strings to the 2nd activity, then i check if it is not a null string, if it is i hide the layout, otherwise it shows, but it is just a copypaste of code. I hope i was clear enough
Thanks everyone for your support

Multiselect Recyclerview List

Good day all,
I have a list of items that i want the user to be able select say 5 out of the 10 items and with all 5 be able to send some data off to a webservice.
i found This and This
but neither of them worked or the GitHub Repo is non existent (the second one).
Does anyone have any other tuts on how to do this?
Thank you
What is going on with your proplem?
Is the video (https://www.youtube.com/watch?v=7du30yAL6rI) as your expectation?
In this example, I create an empty class and simple recyclerview.
The view item will handle user click behaviour. If user selected item the click again the item would not select and otherwise. When this action is happening, we have a listener to send to MainActivity (implemented onItemChangeListener a method of interface that is defined in adapter)
In the MainActivity, I create a layout with recyclerView, delete button, and no items labels. The delete button will process delete and update the list data.
The source code is at: https://github.com/liemvo/Example_RecycleMultiSelected

Highlight and disable Listview items

I have a little Problem with my ListView.
I fill my ListView with an ArrayList<String> per ArrayAdapter<String> with more than 100 items.
Before my dialog will be show i want to highlight and disable some items. I have found the solution with ListView.post(new Runnable() {...});
I highlight my items with lv.getChildAt(2).setBackgroundColor(Color.BLUE);
and disbable an item with lv.getChildAt(3).setEnabled(false);
I do both also in an OnItemClickListener().
Now my problem:
if in the ListView are 11 items visible at runtime, the the highligt- and disable-pattern will repeat every 11 items.
i.e. if i highlight just the 3. item also the 14., 25. ... item will get a blue background.
And if i disable the 4. item also the 15. and 26. and so on is disabled.
If i scroll fast to buttom and back to top other items are highlighted and disabled.
Another problem is, that i can only access the first (11) visible items in the post-runnable. If i try to highlight the 20. item the app will crash with a NullPointerException.
What can i do to prevent the "item-recycling" and to get full access to all items before the Dialog is shown?
I'm not sure i understand what you want to achieve but here are some suggestions for you.
1) Always Recycle, you should never avoid recicling since you maybe run into another problem, you will run out of memory.
2) In your model implement the checkeable interface, so the model should know if an item is selected or not, Not the view only
3) When iterating each element make use of a ViewHolder and then check the model to see if the elment being inflaed it selected or not and use the desired color
Please have a look at this example link, it describes the use of CAB (Contextual Action Bar) but it uses the things i'm mentioning.
I hope it helps you.

Get overall string text of different dynamic views

I have an android fragment that looks something like this:
Every time the user clicks add/remove a new row is added/removed. When they click okay, then I need to return a string for all the views above, for example "TextATextBTextCTextD".
What would be a good way to go about this? I thought about adding tags for each new view, then doing a for loop through each view. But because I have spinners and edit views, I wasn't sure how to get the view for each then get their text.
Any help would be appreciated. Thanks.
Well, your tag option isn't bad... everytime you change one of the view's values, you could set the tag of the view to the string value, then iterate over the views and just collect the tags.
Another way to do it, would be to create your own custom spinner / edittext & make them all implement an interface which has a method called String getDisplayText()
Then, whenever you create a view, place it in an array of that interface type, then iterate over all your objects and call getDisplayText() on all of them.
Hope this helps :)

ListView with few lists in one Activity

I try to put something like menu picker in ListView with only one Activity.
Only one XML file, one Activity one ListAdapter but few lists with items to fill it.
I am trying to do it like this:
on OnItemClickListener, i get item position, save it and open another list , according to our choose.
it's work, but only on first click. When i try choose 1st option 2 times then OnClick method jump from first list to last. When i try pick 1st option and then any other it's work's perfect
But it will be nice to have all options available for all the options on the list :)
any other way to make something like this? or to fix this? of course i can create xml file and activity for every single list, but when you have like 20 different combinations it's not good option :D

Categories