android中的左右滑屏实现
2012-05-25 09:33:38 来源:WEB开发网核心提示:import android.os.Parcelable;009import android.support.v4.view.PagerAdapter;010import android.support.v4.view.ViewPager;011import android.support.v4.view.ViewPa
import android.os.Parcelable;
009
import android.support.v4.view.PagerAdapter;
010
import android.support.v4.view.ViewPager;
011
import android.support.v4.view.ViewPager.OnPageChangeListener;
012
import android.util.Log;
013
import android.view.LayoutInflater;
014
import android.view.View;
015
import android.widget.EditText;
016
017
public class TestViewPager extends Activity {
018
private ViewPager myViewPager;
019
020
private MyPagerAdapter myAdapter;
021
022
private LayoutInflater mInflater;
023
private List<View> mListViews;
024
private View layout1 = null;
025
private View layout2 = null;
026
private View layout3 = null;
027
028
@Override
029
protected void onCreate(Bundle savedInstanceState) {
030
super.onCreate(savedInstanceState);
031
setContentView(R.layout.viewpager_layout);
032
myAdapter = new MyPagerAdapter();
033
myViewPager = (ViewPager) findViewById(R.id.viewpagerLayout);
034
myViewPager.setAdapter(myAdapter);
035
036
mListViews = new ArrayList<View>();
037
mInflater = getLayoutInflater();
038
layout1 = mInflater.inflate(R.layout.layout1, null);
039
layout2 = mInflater.inflate(R.layout.layout2, null);
040
layout3 = mInflater.inflate(R.layout.layout3, null);
041
042
mListViews.add(layout1);
043
mListViews.add(layout2);
044
mListViews.add(layout3);
045
046
//初始化当前显示的view
047
myViewPager.setCurrentItem(1);
048
049
//初始化第二个view的信息
050
EditText v2EditText = (EditText)layout2.findViewById(R.id.editText1);
051
v2EditText.setText("动态设置第二个view的值");
052
053
myViewPager.setOnPageChangeListener(new OnPageChangeListener() {
054
055
@Override
056
public void onPageSelected(int arg0) {
057
Log.d("k", "onPageSelected - " + arg0);
058
//activity从1到2滑动,2被加载后掉用此方法
059
View v = mListViews.get(arg0);
060
EditText editText = (EditText)v.findViewById(R.id.editText1);
061
editText.setText("动态设置#"+arg0+"edittext控件的值");
009
import android.support.v4.view.PagerAdapter;
010
import android.support.v4.view.ViewPager;
011
import android.support.v4.view.ViewPager.OnPageChangeListener;
012
import android.util.Log;
013
import android.view.LayoutInflater;
014
import android.view.View;
015
import android.widget.EditText;
016
017
public class TestViewPager extends Activity {
018
private ViewPager myViewPager;
019
020
private MyPagerAdapter myAdapter;
021
022
private LayoutInflater mInflater;
023
private List<View> mListViews;
024
private View layout1 = null;
025
private View layout2 = null;
026
private View layout3 = null;
027
028
@Override
029
protected void onCreate(Bundle savedInstanceState) {
030
super.onCreate(savedInstanceState);
031
setContentView(R.layout.viewpager_layout);
032
myAdapter = new MyPagerAdapter();
033
myViewPager = (ViewPager) findViewById(R.id.viewpagerLayout);
034
myViewPager.setAdapter(myAdapter);
035
036
mListViews = new ArrayList<View>();
037
mInflater = getLayoutInflater();
038
layout1 = mInflater.inflate(R.layout.layout1, null);
039
layout2 = mInflater.inflate(R.layout.layout2, null);
040
layout3 = mInflater.inflate(R.layout.layout3, null);
041
042
mListViews.add(layout1);
043
mListViews.add(layout2);
044
mListViews.add(layout3);
045
046
//初始化当前显示的view
047
myViewPager.setCurrentItem(1);
048
049
//初始化第二个view的信息
050
EditText v2EditText = (EditText)layout2.findViewById(R.id.editText1);
051
v2EditText.setText("动态设置第二个view的值");
052
053
myViewPager.setOnPageChangeListener(new OnPageChangeListener() {
054
055
@Override
056
public void onPageSelected(int arg0) {
057
Log.d("k", "onPageSelected - " + arg0);
058
//activity从1到2滑动,2被加载后掉用此方法
059
View v = mListViews.get(arg0);
060
EditText editText = (EditText)v.findViewById(R.id.editText1);
061
editText.setText("动态设置#"+arg0+"edittext控件的值");
更多精彩
赞助商链接