引导页

package com.example.zhangjian20170712sharedpreferences02;


import java.util.ArrayList;
import java.util.List;


import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;


public class MainActivity extends Activity {


private ViewPager viewPager;
private Button button;
private List<Integer> list;
private SharedPreferences sharedPreferences;
private Editor edit;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager=(ViewPager) findViewById(R.id.pager);
button=(Button) findViewById(R.id.btn);
//获取对象
sharedPreferences=getSharedPreferences("config", MODE_PRIVATE);
//去文件判断是否进来信息
boolean flag = sharedPreferences.getBoolean("flag", false);
if (flag) {
enterDetails();
return;
}

list=new ArrayList<Integer>();
list.add(R.drawable.a);
list.add(R.drawable.b);
list.add(R.drawable.c);
list.add(R.drawable.d);
list.add(R.drawable.e);

viewPager.setAdapter(new MyPagerAdapter());


viewPager.setOnPageChangeListener(new OnPageChangeListener() {

public void onPageSelected(int position) {
if (position==list.size()-1) {
button.setVisibility(View.VISIBLE);
}else {
button.setVisibility(View.GONE);
}

}

public void onPageScrolled(int arg0, float arg1, int arg2) {


}

public void onPageScrollStateChanged(int arg0) {


}
});

button.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
//拿到文件存储信息
edit = sharedPreferences.edit();
//进入
edit.putBoolean("flag", true);
edit.commit();
enterDetails();

}



});
}


public void enterDetails() {
// TODO Auto-generated method stub
Intent it=new Intent(MainActivity.this,MyActivity.class);
startActivity(it);
//杀死之前的页面
finish();
}

class MyPagerAdapter extends PagerAdapter{


@Override
public int getCount() {
// TODO Auto-generated method stub
return list.size();
}


@Override
public boolean isViewFromObject(View arg0, Object arg1) {
// TODO Auto-generated method stub
return arg0==arg1;
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imageView=new ImageView(MainActivity.this);
imageView.setImageResource(list.get(position));
imageView.setScaleType(ScaleType.FIT_XY);
container.addView(imageView);
return imageView;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// TODO Auto-generated method stub
container.removeView((View) object);
}

}


}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值