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
Related
Let's say I have two activities/classes. MainActivity and SecondActivity. For each of these activities I have individual XML files. In SecondActivity, I have a ListView with ID listview.
How can I retreive the ListView from SecondActivity in MainActivity?
I tried just plain and simple (in MainActivity.java):
ListView listview = (ListView) findViewById(R.id.listview);
But that crashes my app when I try to set an adapter on it (nullPointerException). I tried placing it directly inside my class, and inside the onCreate method. Both causes a crash.
The line that causes the crash looks like this:
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayList);
listview.setAdapter(adapter); //crash (nullpointerexception pointing to nullobject)
What I want to do is get that ListView and use the "listview" object to add elements to the listview in my MainActivity.
In Android (with exceptions) you cannot have more than one activity running at the same time. You can have multiple Fragments, but a single activity is shown at a single time (ok, this is not 100% true anymore, but for all intents and purposes, this is still the case).
What you're trying to do is considered extremely bad practice in Android (and iOS for what is worth).
What can/should you do?
Your requirements appear to be some form of: I have a list of items, and I also have another activity where I want to add or remove things from said list.
This is fine, but you don't need "two activities" to do this.
Have one activity to show the list, and when you want to add the contents, either launch another activity to show the UI of the "edit/add" or use Fragments (one Fragment would have the list, the other would have the UI to edit the list).
Where is the data in all this?
Stored in a THIRD place (let's call it "YourListRepository"), which is a class where:
From the "List" you'd simply say: Repository, give me the latest list!
From the "Edit" screen, you'd say: Repository, give me the item "N" from the list. And then, you'd say: Repository, here's the updated item "N", refresh it.
Going back to 1 (to display the updated list) is automatic, since it asks "for the latest list".
Where to learn more?
Given the tenure of the question you posted, it appears that you're relatively new to Android development, and therefore I suggest you spend an hour of your time, reading Application Fundamentals from the official Google documentation.
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
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));
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
I want to ask one question, should I use ListView inside ListView item? Or I should redesign and remake my idea?
Example of ListView, but should be with couple sub items:
A ListView inside a ListView item is never a good idea. If you want sublists inside your list you can, for example, use a ExpandableListView. However, with the migration from ListViews to RecyclerViews I would recommend you go and implement this instead.
A ListView will never work correctly embedded as an item in another ListView. In fact, scrolling things inside other scrolling things is almost never what you really want to do, as it would be confusing to the user how to actually navigate your screen.