0
我把一個ViewPager放在DrawerLayout中。 現在,當我嘗試滾動ViewPager,菜單關閉DrawerLayout中的ViewPager
請告訴我如何讓菜單不會關閉,當我滾動viewPager
viewPager適配器:
public class MenuNewsAdapter extends PagerAdapter {
ArrayList<News> news = new ArrayList<>();
Context context;
public MenuNewsAdapter(Context context, ArrayList<News> news) {
this.news = news;
this.context = context;
}
@Override
public int getCount() {
return news.size();
}
@Override
public Object instantiateItem(final ViewGroup container, final int position) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.list_menu_news, container, false);
...
rowView.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(container.getContext(), NewsViewActivity.class);
intent.putExtra("news_id", news.get(position).newsId);
container.getContext().startActivity(intent);
}
});
container.addView(rowView);
return rowView;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((LinearLayout) object);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView((LinearLayout) object);
}
}
謝謝。但當我添加點擊監聽器 「rowView.setOnClickListener(new View.OnClickListener(){ public void onClick(View v){」 ,我再次得到問題 –
什麼是rowView? – dumazy
我在第一條消息中添加了代碼 –