I have a TabHost with a ListView inside a tab. When the activity starts, I can't scroll the list view until I have clicked off the tab that the activity starts on, and then re-select the tab with the list view inside it.
Note, I can get the list view to focus by calling:
tabHost.getTabContentView().requestFocus(); but unfortunately, I still can't scroll until I have reselected the tab...
Have any remedies?
Thanks!
Fixed - I ditched the tabs in order to simplify the layout.
Related
I currently have a bottom navigation with 3 items for my 3 activities. I have a separate button on one of the screens that opens a new activity. When this happens, I'd like to program it so none of the 3 options of the bottom navigation view are selected.
bottomNavigationView.setSelectedItemId(R.id.______)
This is the line I use to select which icon I'd like to be shown as currently clicked. If I leave this line out of my activity, the first item of the bottom navigation view is selected by default.
I think that it will be better for you to use fragments for this task.
I am implementing a view with TabLayout and Recycler View.
Each tab will contains individual items in a Recycler View related to currently selected tab.
What I am searching is, I want to remove all items belong to the selected Tab and remove the Tab that pressed delete icon in TabLayout Tab.
I know how to remove a tab from tab layout.
But I do not have any idea, how to show a remove icon on each Tab and when I press remove Icon how can I remove the specific Tab and its Data.
Below given image is from a web view, I have to do exact same thing in Android.
Question in summary,
Add a delete icon to TabLayout.Tab
When click delete icon, that TabLayout.Tab shoul remove from TabLayout.
Please give me some ideas or guides.
Thanks in advance.
I would suggest following way :
During callback of TabLayout.OnTabSelectedListener
Method onTabSelected(TabLayout.Tab tab) will provide you selected tab. so find your close icon from it using findViewById and then set click listener on it.
During method onTabUnselected(TabLayout.Tab tab) you can remove click listener for particular close icon.
During click event of your close button,
You can get selected tab index using getSelectedTabPosition(). So using that index you can remove that tab,
To remove buttons from all of tabs you can iterate through all tabs using combination of getTabAt (int index) & getTabCount () methods from TabLayout then remove it one by one and after that also remove tab and it's data after that in this click listener.
Yes, there's no easy way to do this stuff but it'll help like patchy way.
I have a pretty standard implementation of ViewPager using Fragments; however I'm wondering if it's possible to get rid of the preloading of tabs, and to only load a tab activity once user clicks on it?
Also, can we get rid of the swipe effect, just like in iOS?
Thank you
If you want the user to only click on tabs, then don't use a ViewPager; put the views in a FrameLayout, make them all invisible and only set the view that is selected visible. When the user clicks on a tab, make the current view invisible and selected view visible. Much simpler than implementing a PagerAdapter.
I have implemented the recycler view in navigation drawer in android.This is working fine.I am able to switch between item by clicking on recycler view item.
but i am not able to change the background color for the selected item.please suggest me how to imeplement it.I have tried this so far.
1.Background Selector in RecyclerView Item
Tried to make recycler view clickable,focusable but didn't work
2.http://innodroid.com/blog/post/tracking-selected-item-in-recyclerview
implemented but didn't understand where to write the code for changing background
Please help me out.
What you really need to understand with RecyclerView is that it's not the same control as a Listview with a funky adapter.
RecyclerView does not exhibit many of the ListView's functionalities and whilst it's understandable to compare it to a ListView or a GridView (or event a StaggeredGridView), it shouldn't be confused with them.
With RecyclerView, the responsibilities of handling the "background change" selector relies on the underlying control that the RecyclerView is holding. It's also the same with onClick and many other perks you get for free in a ListView.
Why it is better (or worse) to use a RecyclerView to a ListView is a different matter that I won't go into but to fix your problem, in order to set a background selector on your RecyclerView, add this to the layout that you're inflating in your ViewHolder (i.e. the actual layout that's being used inside the RecyclerView, similar to your "list row item" that you would inflate inside an ArrayAdapter if it were a ListView):
android:clickable="true"
android:background="?android:selectableItemBackground"
Which should set the background appropriately.
Recycler view are recommend when you have very large items & wants to have a custom UI. If you want to display only few items the would recommend to use List View.
hi i created an app. In that when i hit a button it moves over to a new page, the page contains a list of item. The layout has been fixed as if a list view with a scroll view. Once i scroll the page is been changed over to a black screen. Is is this the problem in my coding or it is common to all apps
Add below line to your ListView in xml
android:cacheColorHint="#0000"