forked from JakeWharton/ActionBarSherlock
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request JakeWharton#882 from androidmoney/dev
Navigation spinner doesn't properly scroll to the currently selected item if there are many items in the list
- Loading branch information
Showing
3 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
actionbarsherlock-samples/known-bugs/res/layout/issue882.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:orientation="vertical" | ||
android:padding="5dp" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent"> | ||
|
||
<android.support.v4.view.ViewPager | ||
android:id="@+id/pager" | ||
android:layout_width="match_parent" | ||
android:layout_height="0px" | ||
android:layout_weight="1"/> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:padding="5dp" | ||
android:text="In collapsed mode, select Fragment 10 from the spinner. Tap the spinner again to display the choices. On native, Fragment 10 is shown on the list, on ABS, Fragment 1 is shown instead."/> | ||
|
||
</LinearLayout> |
131 changes: 131 additions & 0 deletions
131
...onbarsherlock-samples/known-bugs/src/com/actionbarsherlock/sample/knownbugs/Issue882.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package com.actionbarsherlock.sample.knownbugs; | ||
|
||
import static android.view.Gravity.CENTER; | ||
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; | ||
import static com.actionbarsherlock.app.ActionBar.NAVIGATION_MODE_TABS; | ||
import android.os.Bundle; | ||
import android.support.v4.app.Fragment; | ||
import android.support.v4.app.FragmentManager; | ||
import android.support.v4.app.FragmentStatePagerAdapter; | ||
import android.support.v4.app.FragmentTransaction; | ||
import android.support.v4.view.ViewPager; | ||
import android.support.v4.view.ViewPager.OnPageChangeListener; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
import android.widget.TextView; | ||
|
||
import com.actionbarsherlock.app.ActionBar; | ||
import com.actionbarsherlock.app.ActionBar.TabListener; | ||
import com.actionbarsherlock.app.SherlockFragment; | ||
import com.actionbarsherlock.app.SherlockFragmentActivity; | ||
|
||
public class Issue882 extends SherlockFragmentActivity implements | ||
OnPageChangeListener, TabListener { | ||
private static final int COUNT = 20; | ||
|
||
ViewPager mPager; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.issue882); | ||
|
||
mPager = (ViewPager) findViewById(R.id.pager); | ||
mPager.setAdapter(new MyAdapter(getSupportFragmentManager())); | ||
mPager.setOnPageChangeListener(this); | ||
|
||
ActionBar ab = getSupportActionBar(); | ||
ab.setNavigationMode(NAVIGATION_MODE_TABS); | ||
for (int i = 1; i <= COUNT; i++) { | ||
ab.addTab(ab.newTab().setText("Fragment " + i).setTabListener(this)); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPageScrolled(int position, float positionOffset, | ||
int positionOffsetPixels) { | ||
} | ||
|
||
@Override | ||
public void onPageSelected(int position) { | ||
getSupportActionBar().setSelectedNavigationItem(position); | ||
} | ||
|
||
@Override | ||
public void onPageScrollStateChanged(int state) { | ||
} | ||
|
||
@Override | ||
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft) { | ||
mPager.setCurrentItem(tab.getPosition()); | ||
} | ||
|
||
@Override | ||
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft) { | ||
} | ||
|
||
@Override | ||
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft) { | ||
} | ||
|
||
public static class MyAdapter extends FragmentStatePagerAdapter { | ||
public MyAdapter(FragmentManager fm) { | ||
super(fm); | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return COUNT; | ||
} | ||
|
||
@Override | ||
public Fragment getItem(int position) { | ||
return BoringFragment.newInstance(position + 1); | ||
} | ||
} | ||
|
||
public static class BoringFragment extends SherlockFragment { | ||
int mNum; | ||
|
||
/** | ||
* Create a new instance of CountingFragment, providing "num" as an | ||
* argument. | ||
*/ | ||
static BoringFragment newInstance(int num) { | ||
BoringFragment f = new BoringFragment(); | ||
|
||
// Supply num input as an argument. | ||
Bundle args = new Bundle(); | ||
args.putInt("num", num); | ||
f.setArguments(args); | ||
|
||
return f; | ||
} | ||
|
||
/** | ||
* When creating, retrieve this instance's number from its arguments. | ||
*/ | ||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
mNum = getArguments() != null ? getArguments().getInt("num") : 1; | ||
} | ||
|
||
/** | ||
* The Fragment's UI is just a simple text view showing its instance | ||
* number. | ||
*/ | ||
@Override | ||
public View onCreateView(LayoutInflater inflater, ViewGroup container, | ||
Bundle savedInstanceState) { | ||
TextView tv = new TextView(getActivity()); | ||
tv.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, | ||
MATCH_PARENT)); | ||
tv.setText("Fragment #" + mNum); | ||
tv.setGravity(CENTER); | ||
return tv; | ||
} | ||
|
||
} | ||
} |