Get focused View from ViewPager not working properly
You can write page change listener class like this:
pager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int pageNum) {
// TODO Auto-generated method stub
Log.d("index", "onpagechange: " + pageNum);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
});
How can I know when focus is on one of the fragments inside the viewpager?
Override this method in fragment
@Override
public void setMenuVisibility(boolean menuVisible) {
super.setMenuVisibility(menuVisible);
//if fragment is visible then menuVisible = true else false
}
Getting current view from ViewPager
You can try something like this -
@Override
public Object instantiateItem(ViewGroup container, int position) {
LayoutInflater inflater;
if(position != 10){
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.viewpager_item, container,
false);
itemView.setTag("View"+position);
} else {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
itemView = inflater.inflate(R.layout.results, container,
false);
}
container.addView(itemView);
return itemView ;
}
And when you need the current view-
View myView = pager.findViewWithTag("View"+pager.getCurrentItem());
Is it possible to access the current Fragment being viewed by a ViewPager?
I finally found an answer that worked for me. Basically, you can access the fragment for a viewPager page by using the tag "android:switcher:"+R.id.viewpager+":0".
Android ViewPager get the current View
I've figured it out. What I did was to call setTag()
with a name to all View
s/ListView
s, and just call findViewWithTag(mytag)
, mytag
being the tag.
Unfortunately, there's no other way to solve this.
How to control focus in child views in viewpager
I found the answer at last and shared it here.
FocusFinder.getInstance().findNextFocusFromRect supports negative parameters, so what we need to do is call it with rect(A1) - (width,0) and rect(A2).
Related Topics
Radiogroup with Two Columns Which Have Ten Radiobuttons
Copy Database from Assets to Databases Folder
How to Check If Receiver Is Registered in Android
How to Add (Vertical) Divider to a Horizontal Linearlayout
Android: How to Detect When a Scroll Has Ended
Upload an Image and Audio in One Request in Android
Android Adb Stop Application Command Like "Force-Stop" for Non Rooted Device
How to Delete SQLite Database from Android Programmatically
How to Automate the Android Sdk Installation
ASP.NET Web API Authentication
Any Way to Link to the Android Notification Settings for My App
I Can't Find the Android Keytool
Adb Connection by Wifi Getting Killed When a New Usb Attached/Detached
Mobile Vision API - Concatenate New Detector Object to Continue Frame Processing