我正在尝试在源代码中实现一个viewPager,并在该行设置一个断点:
if (position > oldPos) {
由于某种原因,当左右滑动viewPager时,我似乎永远不会到达调试器中的断点。我已经多次查看了我的来源,而且我似乎无法准确找出造成这种情况的原因。
非常感谢任何建议。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
final ActionBar actionBar = getActionBar();
final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setAdapter(adapter);
actionBar.setCustomView(R.layout.actionbar_custom_view_home);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
drawerListViewItems = getResources().getStringArray(R.array.items);
drawerListView = (ListView) findViewById(R.id.left_drawer);
drawerListView.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_listview_item, drawerListViewItems));
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */
drawerLayout, /* DrawerLayout object */
R.drawable.ic_drawer, /* nav drawer icon to replace 'Up' caret */
R.string.drawer_open, /* "open drawer" description */
R.string.drawer_close /* "close drawer" description */
);
drawerLayout.setDrawerListener(actionBarDrawerToggle);
getActionBar().setDisplayHomeAsUpEnabled(true);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
GravityCompat.START);
listView = (VideosListView) findViewById(R.id.videosListView);
listView.setOnVideoClickListener(this);
new GetYouTubeUserVideosTask(responseHandler, playlist).execute();
setOnPageChangeListener(mPageChangeListener);
final ViewPager.SimpleOnPageChangeListener mPageChangeListener = new ViewPager.SimpleOnPageChangeListener() {
@Override
public void onPageSelected(final int position) {
onTabChanged(mPager.getAdapter(), mCurrentTabPosition, position);
mCurrentTabPosition = position;
int oldPos = viewPager.getCurrentItem();
if (position > oldPos) {
// Moving to the right
String playlist = "TheMozARTGROUP";
new GetYouTubeUserVideosTask(responseHandler, playlist)
.execute();
View vg = findViewById(R.layout.home);
vg.invalidate();
} else if (position < oldPos) {
// Moving to the Left
String playlist = "TheMozARTGROUP";
new GetYouTubeUserVideosTask(responseHandler, playlist)
.execute();
View vg = findViewById(R.layout.home);
vg.invalidate();
}
}
private void onTabChanged(PagerAdapter adapter,
int mCurrentTabPosition, int position) {
// TODO Auto-generated method stub
}
};
}
private void setOnPageChangeListener(
OnPageChangeListener mPageChangeListener2) {
// TODO Auto-generated method stub
}
Handler responseHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
populateListWithVideos(msg);
};
};
private void populateListWithVideos(Message msg) {
Library lib = (Library) msg.getData().get(
GetYouTubeUserVideosTask.LIBRARY);
listView.setVideos(lib.getVideos());
}
@Override
protected void onStop() {
responseHandler = null;
super.onStop();
}
@Override
public void onVideoClicked(Video video) {
Intent intent = new Intent(this, Player.class);
intent.putExtra("id", video.getId());
intent.putExtra("title", video.getTitle());
intent.putExtra("uploader", video.getUploader());
intent.putExtra("viewCount", video.getviewCount());
startActivity(intent);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
actionBarDrawerToggle.onConfigurationChanged(newConfig);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class ImagePagerAdapter extends PagerAdapter {
public ImagePagerAdapter(Activity act, int[] mImages,
String[] stringArra) {
imageArray = mImages;
activity = act;
stringArray = stringArra;
}
// this is your constructor
public ImagePagerAdapter() {
super();
}
private int[] mImages = new int[] { R.drawable.selstation_up_btn,
R.drawable.classical_up_btn, R.drawable.country_up_btn,
R.drawable.dance_up_btn, R.drawable.hiphop_up_btn,
R.drawable.island_up_btn, R.drawable.latin_up_btn,
R.drawable.pop_up_btn, R.drawable.samba_up_btn };
private String[] stringArray = new String[] { "vevo",
"TheMozARTGROUP", "TimMcGrawVEVO", "TiestoVEVO",
"EminemVEVO" };
@Override
public int getCount() {
return mImages.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((ImageView) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
Context context = Home.this;
ImageView imageView = new ImageView(context);
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setImageResource(mImages[position]);
((ViewPager) container).addView(imageView, 0);
return imageView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
((ViewPager) container).removeView((ImageView) object);
}
protected void onTabChanged(final PagerAdapter adapter,
final int oldPosition, final int newPosition) {
// Calc if swipe was left to right, or right to left
if (oldPosition > newPosition) {
// left to right
} else {
// right to left
}
final ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);
}
}
}
答案 0 :(得分:0)
断点到底在哪里?如果它在方法扩展上,它可能不会被触发,具体取决于您的IDE。尝试将它放在方法本身中,所以在你的情况下在行:
**breakpoint** if (position > oldPos) {
答案 1 :(得分:0)
您永远不会调用该代码。该行位于onTabChanged内部,该行仅由mPageChangeListener调用,从未使用过。所以当然,你永远不会达到那个断点。