I'm currently developing an app in android.
I have a really basic listview that has 3 elements in his adapter:
1 imageview and 2 textviews.
These 3 items are inside a constraint layout.
All i ask is if i can make this layout (imgview + 2 tview) scrollable horizontally.
I've tried adding the layout to a horizontalscrollview, it works but i can't take the list onclicklistener.
I assume you want to be able to click on a list item? You could try adding a click listener to the scrollView. You probably also need to set clickable = true on the scrollview (not sure which is the default) and also just in case set clickable = false to all 3 child elements so they don't "eat" the click instead of the scrollView.
Use RecyclerView instead, you can add the onClickListener inside the adapter itself, or if you want the clickListener to be more interactive between your adapter and your activity/fragment, you can try using interface inside the adapter.
Related
I'm making my first java android app and I'm having some issues with the RecyclerView.
I have a RecyclerView with a custom layout for each element.
I want to make that when I press the toolbar button, the Image Buttons inside EACH layout element inside the RecyclerView turn visible or invisible
This is the toolbar edit button code:
ArrayList<View> dest=new ArrayList<View>();
recView= findViewById(R.id.newListView);
recView.setItemViewCacheSize(0);
recView.findViewsWithText(dest,getString(R.string.onesingleuserlayout),View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
for (View oneUserLayout:dest)
{
oneUserLayout.findViewById(R.id.btnDelete).setVisibility(newVisibility);
oneUserLayout.findViewById(R.id.btnEdit).setVisibility(newVisibility);
}
It hides almost all the elements, but not every one of them. The ones shown behave correctly, and SOMETIMES the ones not showing don't.
I think that it is related to the cached items.
Remove this line, in order to permit caching:
recView.setItemViewCacheSize(0);
Here it's explained how it works (which may also explain, why caching is required).
Try to change your approach and instead of calling all those findView methods from outside the RecyclerView, implement a method on the adapter to change a boolean variable representing the visibility of the buttons and then call notifyDataSetChanged to force the layout manager to redraw all the visible itens and since all items reference the boolean variable, when new items are redrawn they will have the new visibility.
I've 2 layouts on my project. Both have a button to swap between each other using setContentView method. Whenever I swap between these 2 layouts, every UI element I've added using addView() is lost. However static XML elements remains.
That's because the layout is inflated anew, with all the views specified in the xml when you call setContentView(R.layout.xml), that's happening behind the scenes, and all the dynamically added views will be gone.
Optional solutions:
Add the views again after you call setContentView().
The 2 layouts can live on top of each other and you can toggle their visibility. use GONE to hide the layout, not INVISIBLE If the layouts have clickable elements on them.
I have a listView that contains my data, but instead of scrolling using the scroll bar, i need to be able to press a button to scroll up (if the listview can scroll up) and a button to scroll down (if the listview can scroll down)
Anyone know how i would go about this? I have checked the listView, and there seems to be no function to scroll up or down.
Ideally i would like to know if there are properties against a listView that tell me the
Maximum Y position that the listView can go to
Current Y postition that the listView is scrolled to
Using these values i can code the rest.
In the end, i removed the listView, and used a ScrollPane with a VBox. Then i added my items to the VBox instead. I had to make changes to the items i was adding to the listView originally, but this seems to work nicely.
I can now use the get/set property VMin, VMax and Vvalue on the scrollPane.
There is Flowless which acts as a simplified(*) (and more efficient) ListView. It has scrollX(dx) and scrollY(dy) methods that you can use to scroll the content.
(*) It does not support selection and inline editing out of the box, but can be implemented on top of it.
Below is a picture of my app, I am currently using a modified version of this app to show my expandable content. Now my problem is with my ImageView, I currently have 3 layouts, one for the main dialog (with listview), one for the listview title & arrow and one for the item details (item row once expanded). I want to add animation to the ImageView so when you click the image or title textview, the list will expand and animate the change. How can I do this? I cannot get the onClick to work because it doesn't know there are 2 imageviews, it seens only one...
I will assume that your ImageView is this arrow inside your ListView element (because you didn't write it clearly enough).
You probably shouldnt try to attach onClickListener to your ImageView at all (nor to your ListView element title). The good way of implementing what you want you achieve would be to use ListView's onItemClickListener to detect clicks performed on specific items inside your listview, and then expanding appropriate expandable content.
i am using Listview inside the Scroll view. and this Listview is the last item of scroll view. Problem is when data gets load the scroller move down to the bottom. How can i prevent it from scrolling on loading data.
You shouldn't use a ListView inside a ScrollView as they are both scrollable.
However to solve your problem I guess you should use the attribute android:descendantFocusability="blocksDescendants" for your main container which resides in the ScrollView.