Im using nhaarman's ListviewAnimation library https://github.com/nhaarman/ListViewAnimations which works great.
Though I have difficulty tweaking one of his options, which is ExpandableListview. I want to tweak it so that only 1 child view (content view)is visible at a time. So when expanding a parent view (title view) item it should close the previous one. I can't seem to update (notify) my adapter when a child view is visible (is expanded). I have a custom adapter which extends ExpandableListItemAdapter.
This is the class here .
Each item is set with the TitleViewOnClickListener, which handles the expanding ad collapsing of the content view.
Now I would like to collapse all visible child views and keep the selected open. Could anyone here help me or guide me in the right direction?
Next to that I can't seem to get an onlistitem click.
Thank you in advance
I've added a setLimit(int) function to the ExpandableListItemAdapter class. When the (limit+1)th item is expanded, the first expanded item will collapse.
In your case, you could call setLimit(1).
You can use:
#Override
public int getChildrenCount(final int groupPosition) {
return 1;
}
Related
I know it's a little bit generic. So I have a recyclerView, and inside it there are multiple items which can expand and collapse (each of them has a webview and expand and collapse to decide if the full content needs to be shown). I need to set images for a BiImageView in the viewAdapter like this
ItemViewHolder viewHolder = (ItemViewHolder) recyclerView
.findViewHolderForLayoutPosition(position);
viewHolder.rightIndicator.setImageResources()
However it only works when every item is collapsed, when the first item expand, it will take up the screen and other items will be hidden or say below the bottom of the screen. Then only the first few items can set the image resource. For other hidden items, the viewHolder is null. It looks like recyclerView removed them from layout, I'm wondering if there is any way to make sure I can get the viewHolder? Like some callback? I tried onCreate and onBind, but when I scroll down or collapse the first item, these two methods didn't get called.
I think, I can help you with some pseudo code, but I dont remember how to use it with view model. First of all, you have to change all your views in onBindViewHolder method in depend on your model, then in your model class you must have field, for example
boolean expanded = false; // initial state
And in your onBindViewHolder:
if (modelsList.get(position).isExpanded()){
//show expanded view
} else {
//show collapsed view
}
After it, you can set onClickListener to some view in your collapsed view, to expand:
view.setOnClickListener(new OnClickListener(){
public void onClick(View v){
modelsList.get(position).setIsExpanded(!modelsList.get(position).getIsExpanded());
MyAdapter.this.notifyItemChanged(position);
}
When you will click on this view, your model will change and RecyclerView will recreate view binded to this model with new data.
Hope it will help you
I am trying to achieve the following. My app will have some views. All of the views are simple textViews which when clicked will be redirected to another activity. But the last view needs to expand to show hidden views. the sub views can further have more sub categories. To be more clear i have attached an image to explain this more detail. 1
So here views 1 - 3 are normal text views. view 4 has sub categories sub view 4.1 till 4.3. these can have further sub categories like 4.1.1, 4.1.2. Also when 4.1 is expanded and user clicks on 4.2 to expand it, 4.1 should automatically collapse then 4.2 should expand. I tried using expandable list view for this purpose buy the rest of my views are not list items. Please help me acheive this. Right now m using text vies and using its visibility to hide or show the views. This is not getting me the desired result. Thanks in advance
It is expandable listview you can use following tutorial
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
and for to collapse automatically all except selected one use this code
private int lastExpandedPosition = -1;
private ExpandableListView lv; //your expandable listview
...
lv.setOnGroupExpandListener(new OnGroupExpandListener() {
#Override
public void onGroupExpand(int groupPosition) {
if (lastExpandedPosition != -1
&& groupPosition != lastExpandedPosition) {
lv.collapseGroup(lastExpandedPosition);
}
lastExpandedPosition = groupPosition;
}
});
Hopefully it will fullfil your requirements.
You can try with NLevelListView best example for multilevel parent and child listview , But need to make data list according below example of Github
https://github.com/triggs/NLevelExpandableListView/tree/master/src/com/twocentscode/nlevelexpandablelistview
I've working on app that need custom list view...
List view should act like some kind of vertical gallery.
In gallery selected item is always on center.
In my app I use navigation keys only or remote controller.
So there is no fling or regular scrolling effect.
I need for example second element in my list to be selected always.
If I want to move up, all elements are scrolled one place up, and selected item has to be changed, but on same place on the screen like previous selected item.
It's the same thing like gallery only vertical.
Is there a simple way to do this?
Is there a vertical gallery implementation?
How can I make gallery widget vertical?
Or how to customize list view to act like that?
Tnx!
try setting onClick Listener on ListView
ListView listView1=(ListView) findViewById(R.id.listView1);
then implemt a class class SearchItemClickListener implements OnItemClickListener
and set listview.onItemClickListenr you will get position and view.
Hope this helps
You can get the current visible first postion by using,
mListView.getFirstVisiblePosition();
after getting the current visible position and its respective data, you can perform your desired task (i.e. display the large image after getting the thumbnail or something like this).
OR
If you don't want to depend on only first or last position and want to select some other visible row then you can do something like this,
public View getView(int position, View convertView, ViewGroup parent)
{
int visiblePosition = position % nObjects; // nObjects if the total number of objects to display
if(visiblePosition == yourDesiredPosition){
// do your custom work here.
}
}
Here is a demo for vertical slide show,
Hope this will give you some hint about implementing your functionality.
I've managed this using setSelected() method on ListView item...and managing key listener.
Didn't found smarter way to handle this.
Here's what I want to do:
I have this list of tasks. When I click on one of the items I want this to appear:
Assuming that menubar can be found with
findViewById(R.id.menubar);
Can someone please tell what code I have to put onItemClickListener
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
NOTE: The menubar visibility its set as GONE.
Thanks!
Without looking at the code, a precise answer is not possible. However, when I first wanted to implement a "Quick Action Bar" similar to the one you have shown, I had followed this example here:
http://code.google.com/p/simple-quickactions/
And this with some styling put in: https://github.com/lorensiuswlt/NewQuickAction3D
Hope this helps....
It is a bit difficult without seeing any code, but I can give you some logic ideas.
Based on your description, I'm assuming that those quick bar controls are hidden on EACH listview item so, it goes:
Fotos (visible)
Action Controls (hidden)
[End of Item]
PROJECTOS (visible)
Action Controls (hidden)
...
I think the OnItemClick method gives you the view (item: Fotos, Projectos, etc) that was clicked as the 2nd argument. If you cast that back to whatever layout you used to create the listview items, you should be able to use findViewByID to get access to the hidden controls that are on each listview and make them visible.
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
//Assuming each item is a linear layout
LinearLayout itemAsLL = (LinearLayout)view;
//find the action bar controls
LinearLayout actionControlsLayout = itemAsLL.findViewById(R.name.of.actioncontrols.id);
//Make it visible
actionControlsLayout.setVisibility(VIEW.Visible);
}
You would need to find a way to hide those controls when another item is clicked? Maybe save the view (or position in the adapterView ) as a class variable and when another item is clicked, go to that view/find that view and hide the controls.
I finally found out the answer. Apparently, when you fill a view with lots of tasks, the adapter does not fill everything when you load the layout, so everytime you scroll down, hes putting more items on the listview.
What you have to do is make sure you put a field "loaded" and, in case is false, it does not show the menubar below that item, otherwise, when you click in one of the items of that list, when you scroll down, since they will have the same relative position (if you click on the first item, the position = 0, when you scroll down, there will be another position = 0) the menubar will appear on both items.
Hope it helps ;)
What I want to do is to scroll view after listening a button.
Simply user taps button and view is scrolled to specific id below.
I tried to use scrollto and scrollby passing as an argument reference to object to which I want to scroll with no effect.
Anyone solved this problem yet?
I have spent many hours on this.
Try something like this. It makes sure that the item selected it the one in view:
ListView listView;
int positionSelected = listView.getSelectedItemPosition();
listView.setSelection(positionSelected);