I'm newbie on android development and developing a app to improve myself.
My app is listing students from db with ListView. I want to do"When I click the name of student, it will show the exam grades" I mean,I want to add new listview to onclick of list item.
Is it possible? What I need to do that(in xml and code),Do you have any code sample?
Create a custom listview (http://www.vogella.com/articles/AndroidListView/article.html) Add a listview to the listview item and set its visibility to GONE. When they click the item set the visibility to VISIBLE.
Add an OnItemClickListener listener in the current ListView and when you get the click event query your data base for that particular student to get result. Once you have result you can load a new ListView in same Activity using Fragment or in a totally new fragment. (You are already using a ListView, so obviously you know how to load data in ListView).
If you want to show the grades in a separate screen, I would suggest that you'll create a new Activity with it's own layout (that will contain the grades ListView) and when a click on a student name will occur you will start the new Activity to display grades (you can pass the student id on the new Activity Intent).
You can also consider using Fragments. This way you will be able to change the layout to master-detail view (like in mail apps) easily on tablets. You can start by looking at this link.
Related
I created a player list program, now according to the program I created, there is a button (at start_activity) when the program starts. clicking on this button will open a list created by the next "recyclerview". I have a question about how to put two buttons (to "start_activity") ("new stars" and "historical stars") and connect both to one recyclerview, the list design will be the same for both, only the names in the list will change . is it possible to use the same recyclerview for both to make it much simpler? how please show an example from the code. Thank you.
It's simple.
On first button click - get your list data & set an adapter in a recyclerview.
On second button click - get your other list data & set an adapter in the same recyclerview.
So your data will be updated. You just have to initialize new data & adapter on button click, then set adapter in the recyclerview.
I have a recipe app which contains list of recipes like when i click burger it display burger recipe on new Activity.
So how to do this by creating single activity with different recipes for every list items?
I have store recipes on firebase.
you can use fragment to show the recipe on same activity
Prehaps showing some code could tell us what you already have?
I don't think you can do it all in one activity.(or at least it wouldn't look good). You can use a recycler view and each time an item on that view is clicked, you can create a new activity to display the details.
Or you can also use fragments and use a master-detail pane.
make an activity which contains textview and imageviews according to your recipe items and pass the data to that activity on click of recyclerview through intent and then on that activity get that data from i,tent and set on the textview and imageviews
I am new to Android development. I used listview with edittext in an activity and I want to call edited listview items one by one in order in another activity. How can I do this?
How can I use listview items added by users for another activitiy. For example in my first activity, users add names as much as they want, in second activity, I should display first item added in textview then second item added in textview then third etc. Unfortunately, there is no code. I ll just start. Thanks a lot
I have a main activity which has a listview and a Fab by which user adds new things to the list view then after clicking the dynamically added listview the user can add more elements into the inner listview.
Think of an app like which has blank initial then a person adds two three countries clicks on a country then he can states/cities to it in a dynamical list view how do i achieve this.
This is a normal situation later I realized it. The first listview retrieves all the countries from the data base and you can add it to the databases too. Then touching on the listview gives set on item click listener then that particular list can be easily taken from the list. This list now contains all from that particular database.
I'm building an android app and I'm trying to replace a list view with another list view if you click a button, like the notifications page on Instagram. On that page, if you click on the top "following" button it will show you a listview of what your followers have liked. If you click on the "you" button it will show you a listview of what people have liked your photos.
Any help would be greatly appreciated!
You can do it by following ways,
1. add Two listviews and can change the visibility as per your requirement.
2. On button click you can load the other data into same list view and can update your adapter in the same list view.
in 1 you have to load two list view at first which will consume more time if data is larger sure you can write a login in asynctask to load list views in background thread.
in 2 you have to update your adapter at the button so you will have to provide some progress bar of dialog for user while you list view is getting update.
You can use either of this whichever suites you best.
Simply , You don't need to switch Listview , you only need to switch adapters .
eg, you can switch to mFollowingAdapter when clicked on Following button and switch to mYouAdapter when you select "You" tab. that's it.
You should write a list, that has a custom adapter. This adapter will be able to display BOTH views you want to display.
If the data to be displayed is the same format (ie. both have an imageview next to a textview), you are in good shape.
When you want to switch to a different list, get the information you would like to display, replace the data in your the collection backing your list, then notify the list that the data has changed, and it should redraw.
So, this might look like:
create ArrayList() with data A
setup List, with this data and display
replace the ArrayList() with data B
call listView.notifyDataSetChanged
You can still do this if the Data A, and Data B have different views, in this case, you would need to handle this logic in your custom adapter.