我无法在网格视图寻呼机中设置当前项目。这是我的代码:
sql injection
适配器类
public class GridActivity extends Activity {
private GridAdapter GridAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_grid);
final Resources res = getResources();
final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
GridAdapter = new GridAdapter(this, getFragmentManager());
pager.setAdapter(GridAdapter);
pager.setCurrentItem(0, 1);
DotsPageIndicator dotsPageIndicator = (DotsPageIndicator) findViewById(R.id.page_indicator);
dotsPageIndicator.setPager(pager);
};
}
我正在寻呼机上设置当前项目,但它不起作用,它始终在第一页上启动。
答案 0 :(得分:3)
我在设置适配器后找到了这样的解决方法:
pager.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
pager.setCurrentItem(0, position, false);
pager.getAdapter().notifyDataSetChanged();
pager.removeOnLayoutChangeListener(this);
}
});