Skip to content

Commit

Permalink
修复BannerComponent 的adapter的count为0 的bug
Browse files Browse the repository at this point in the history
优化FragmentListPageAdapter count为很大的数情况,SparseArray代替ArrayList
  • Loading branch information
LuckyJayce committed Aug 11, 2016
1 parent 62df000 commit 018405e
Show file tree
Hide file tree
Showing 8 changed files with 247 additions and 211 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion app/src/main/java/com/shizhefei/indicator/BannerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,22 @@ protected void onCreate(Bundle arg0) {
bannerComponent = new BannerComponent(indicator, viewPager, false);
bannerComponent.setAdapter(adapter);

findViewById(R.id.button3).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
images = new int[]{};
adapter.notifyDataSetChanged();
}
});

findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
images = new int[]{R.drawable.p2, R.drawable.p3, R.drawable.p4};
images = new int[]{R.drawable.p2};
adapter.notifyDataSetChanged();
}
});

findViewById(R.id.button2).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down
30 changes: 11 additions & 19 deletions app/src/main/java/com/shizhefei/indicator/year/YearActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.shizhefei.indicator.DisplayUtil;
Expand Down Expand Up @@ -36,15 +35,16 @@ public void onCreate(Bundle savedInstanceState) {
indicator.setScrollBar(new SpringBar(getApplicationContext(), Color.GRAY));
viewPager.setOffscreenPageLimit(4);
indicatorViewPager = new IndicatorViewPager(indicator, viewPager);
indicatorViewPager.setAdapter(new YearAdapter(1800, 2100));
indicatorViewPager.setCurrentItem(2016 - 1800, false);
indicatorViewPager.setAdapter(new YearAdapter(1800, 10000000));
indicatorViewPager.setCurrentItem(2016-1800, false);
}

private class YearAdapter extends IndicatorViewPager.IndicatorViewPagerAdapter {
private class YearAdapter extends IndicatorViewPager.IndicatorFragmentPagerAdapter {
private int startYear;
private int endYear;

public YearAdapter(int startYear, int endYear) {
super(getSupportFragmentManager());
this.startYear = startYear;
this.endYear = endYear;
}
Expand All @@ -62,20 +62,12 @@ public View getViewForTab(int position, View convertView, ViewGroup container) {
}

@Override
public View getViewForPage(int position, View convertView, ViewGroup container) {
if (convertView == null) {
convertView = getLayoutInflater().inflate(R.layout.fragment_tabmain_item, container, false);
}
final TextView textView = (TextView) convertView.findViewById(R.id.fragment_mainTab_item_textView);
textView.setText(" " + position + " 界面加载完毕");
final ProgressBar progressBar = (ProgressBar) convertView.findViewById(R.id.fragment_mainTab_item_progressBar);
new Handler() {
public void handleMessage(android.os.Message msg) {
textView.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}.sendEmptyMessageDelayed(1, 3000);
return convertView;
public Fragment getFragmentForPage(int position) {
YearFragment yearFragment = new YearFragment();
Bundle a = new Bundle();
a.putInt(YearFragment.INTENT_INT_POSITION, position);
yearFragment.setArguments(a);
return yearFragment;
}

@Override
Expand Down
38 changes: 38 additions & 0 deletions app/src/main/java/com/shizhefei/indicator/year/YearFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.shizhefei.indicator.year;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.shizhefei.fragment.LazyFragment;
import com.shizhefei.indicator.demo.R;

/**
* Created by LuckyJayce on 2016/8/11.
*/
public class YearFragment extends LazyFragment {
public static final String INTENT_INT_POSITION = "intent_int_position";

@Override
protected void onCreateViewLazy(Bundle savedInstanceState) {
super.onCreateViewLazy(savedInstanceState);

Log.d("pppp", "onCreateViewLazy " + this+" "+savedInstanceState);

int position = getArguments().getInt(INTENT_INT_POSITION);

setContentView(R.layout.fragment_tabmain_item);
final TextView textView = (TextView) findViewById(R.id.fragment_mainTab_item_textView);
textView.setText(" " + position + " 界面加载完毕");
final ProgressBar progressBar = (ProgressBar) findViewById(R.id.fragment_mainTab_item_progressBar);
textView.postDelayed(new Runnable() {
@Override
public void run() {
textView.setVisibility(View.VISIBLE);
progressBar.setVisibility(View.GONE);
}
}, 3000);
}
}
11 changes: 10 additions & 1 deletion app/src/main/res/layout/activity_banner.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,23 @@
android:layout_marginTop="60dp"
android:gravity="center">

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="变为0个" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:text="变为3个" />
android:text="变为1个" />

<Button
android:id="@+id/button2"
Expand Down
Loading

0 comments on commit 018405e

Please sign in to comment.