android,ViewPager实现左右滑动显示页面,这里怎么修改啊??
publicclassMainActivityextendsActivity{privateViewPagermViewPager;List<View>viewList;...
public class MainActivity extends Activity {
private ViewPager mViewPager;
List<View> viewList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutInflater mInflater = getLayoutInflater().from(this);
View v1 = mInflater.inflate(R.layout.layout1, null);
View v2 = mInflater.inflate(R.layout.layout2, null);
View v3 = mInflater.inflate(R.layout.layout3, null);
//??????
viewList = new ArrayList<View>();
viewList.add(v1);
viewList.add(v2);
viewList.add(v3);
//??????
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(new MyPagerAdapter(viewList)); ///////这里怎么修改啊??没有这个类
mViewPager.setCurrentItem(0); //???????
View view = viewList.get(0);
TextView textView = (TextView) view.findViewById(R.id.text_1);
textView.setText("?????");
Button button = (Button) view.findViewById(R.id.button_1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "??????",
Toast.LENGTH_SHORT).show();
}
});
}
} 展开
private ViewPager mViewPager;
List<View> viewList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LayoutInflater mInflater = getLayoutInflater().from(this);
View v1 = mInflater.inflate(R.layout.layout1, null);
View v2 = mInflater.inflate(R.layout.layout2, null);
View v3 = mInflater.inflate(R.layout.layout3, null);
//??????
viewList = new ArrayList<View>();
viewList.add(v1);
viewList.add(v2);
viewList.add(v3);
//??????
mViewPager = (ViewPager) findViewById(R.id.viewpager);
mViewPager.setAdapter(new MyPagerAdapter(viewList)); ///////这里怎么修改啊??没有这个类
mViewPager.setCurrentItem(0); //???????
View view = viewList.get(0);
TextView textView = (TextView) view.findViewById(R.id.text_1);
textView.setText("?????");
Button button = (Button) view.findViewById(R.id.button_1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "??????",
Toast.LENGTH_SHORT).show();
}
});
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询