package com.example.zuoye1017;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.PagerAdapter;
import androidx.viewpager.widget.ViewPager;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
public class MainActivity extends AppCompatActivity {
private ViewPager vp;
private List<String> list = new ArrayList<>();
private Button bt;
private int index = 0;
private Handler handler = new Handler();
private Timer timer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
vp = (ViewPager) findViewById(R.id.vp);
bt = (Button) findViewById(R.id.bt);
vp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
if (position==list.size()-1){
timer.cancel();
}
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
index++;
handler.post(new Runnable() {
@Override
public void run() {
vp.setCurrentItem(index%list.size());
}
});
}
},0,1000);
for (int i = 1; i < 4; i++) {
list.add("第"+i+"个小朋友");
}
vp.setAdapter(new PagerAdapter() {
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
return view==object;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
View inflate = View.inflate(MainActivity.this, R.layout.item, null);
TextView textView = inflate.findViewById(R.id.tv);
textView.setText(list.get(position));
Button button = inflate.findViewById(R.id.bt);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
startActivity(intent);
}
});
container.addView(inflate);
return inflate;
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
container.removeView((View) object);
}
});
}
}
package com.example.zuoye1017;
import androidx.appcompat.app.AppCompatActivity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Main2Activity extends AppCompatActivity {
private EditText et1;
private EditText et2;
private EditText et3;
private Button bt;
private SQLiteDatabase readableDatabase;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
et1 = (EditText) findViewById(R.id.et1);
et2 = (EditText) findViewById(R.id.et2);
et3 = (EditText) findViewById(R.id.et3);
bt = (Button) findViewById(R.id.bt);
SqliteHlep sqliteHlep = new SqliteHlep(this);
readableDatabase = sqliteHlep.getReadableDatabase();
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String yhm = "[0-9]{12,18}";
String mima = "[0-9]{12,18}";
String s = et1.getText().toString();
String s1 = et2.getText().toString();
String s2 = et3.getText().toString();
if (s.matches(yhm)){
Toast.makeText(Main2Activity.this, "请输入下一个", Toast.LENGTH_SHORT).show();
if (s1.matches(mima)){
Toast.makeText(Main2Activity.this, "请在次验证密码", Toast.LENGTH_SHORT).show();
if (s2.equals(s1)){
ContentValues contentValues = new ContentValues();
contentValues.put("yhm",s);
contentValues.put("mima",s1);
readableDatabase.insert("user",null,contentValues);
Intent intent = new Intent(Main2Activity.this,Main3Activity.class);
startActivity(intent);
}
}else{
Toast.makeText(Main2Activity.this, "输入格式不正确", Toast.LENGTH_SHORT).show();
}
}else{
Toast.makeText(Main2Activity.this, "用户名格式不正确", Toast.LENGTH_SHORT).show();
}
}
});
}
}
package com.example.zuoye1017;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Main3Activity extends AppCompatActivity {
private EditText et;
private EditText et1;
private Button bt;
private SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
et = (EditText) findViewById(R.id.et);
et1 = (EditText) findViewById(R.id.et1);
bt = (Button) findViewById(R.id.bt);
SqliteHlep sqliteHlep = new SqliteHlep(this);
db = sqliteHlep.getReadableDatabase();
bt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String yhm = "[0-9]{12,18}";
String s = et.getText().toString();
String s1 = et1.getText().toString();
if (s.matches(yhm)){
Toast.makeText(Main3Activity.this, "请输入密码", Toast.LENGTH_SHORT).show();
Cursor user = db.query("user", null, null, null, null, null, null);
if (user!=null){
while(user.moveToNext()){
String yhm1 = user.getString(user.getColumnIndex("yhm"));
String mima = user.getString(user.getColumnIndex("mima"));
if (yhm1.equals(s)&&mima.equals(s1)){
Intent intent = new Intent(Main3Activity.this,Main4Activity.class);
startActivity(intent);
}else{
Toast.makeText(Main3Activity.this, "123", Toast.LENGTH_SHORT).show();
}
}
}
}
}
});
}
private class MainA4ctivity {
}
}
package com.example.zuoye1017;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.Manifest;
import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class Main4Activity extends AppCompatActivity {
private Uri rui;
private List<String> list = new ArrayList<>();
private ListView listView;
private static final String TAG = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main4);
requestPermissions(new String[]{Manifest.permission.READ_CONTACTS,Manifest.permission.WRITE_CONTACTS,Manifest.permission.CALL_PHONE},100);
listView = findViewById(R.id.lv);
add();
listView.setAdapter(new BaseAdapter() {
private LayoutInflater layoutInflater = LayoutInflater.from(Main4Activity.this);
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int i) {
return list.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if (view==null){
viewHolder = new ViewHolder();
view = layoutInflater.from(Main4Activity.this).inflate(R.layout.item1,null);
viewHolder.tvo = view.findViewById(R.id.tvOne);
viewHolder.tvw = view.findViewById(R.id.tvTwo);
view.setTag(viewHolder);
}else{
viewHolder = (ViewHolder) view.getTag();
}
viewHolder.tvo.setText(list.get(i));
return view;
}
});
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(Main4Activity.this, "吐司", Toast.LENGTH_SHORT).show();
}
});
}
private void add() {
ContentResolver contentResolver = getContentResolver();
rui = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
Cursor query = contentResolver.query(rui, null, null, null, null, null);
if (query!=null){
while(query.moveToNext()){
String name = query.getString(query.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
String sjh = query.getString(query.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
list.add(name);
list.add(sjh);
Log.i("TAG", "onCreate: "+list);
}
}
}
private class ViewHolder {
private TextView tvo,tvw;
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode==100&&grantResults[0]== PackageManager.PERMISSION_GRANTED){
add();
}
}
}
package com.example.zuoye1017;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;
import java.util.ArrayList;
public class MyPagerAdapter extends PagerAdapter {
private ArrayList<View> list;
private Context context;
public MyPagerAdapter(ArrayList<View> list, Context context) {
this.list = list;
this.context = context;
}
@Override
public int getCount() {
return list.size();
}
@Override
public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
return view==o;
}
@NonNull
@Override
public Object instantiateItem(@NonNull ViewGroup container, int position) {
Log.i("aaaaa", position+"加载了: ");
container.addView(list.get(position));
return list.get(position);
}
@Override
public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
Log.i("aaaaa", position+"溢出了: ");
container.removeView(list.get(position));
}
}
package com.example.zuoye1017;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;
public class SqliteHlep extends SQLiteOpenHelper {
public SqliteHlep(@Nullable Context context) {
super(context, "sjk", null, 1);
}
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {
sqLiteDatabase.execSQL("create table user(yhm varchar(30),mima varchar(30))");
}
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/vp"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main2Activity">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="用户名为手机号"
android:id="@+id/et1"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="密码"
android:id="@+id/et2"
android:gravity="center"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="确认密码"
android:id="@+id/et3"
android:gravity="center"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="进入登陆页面"
android:id="@+id/bt"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main3Activity">
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入用户名"
android:id="@+id/et"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="请输入密码"
android:id="@+id/et1"
/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登陆"
android:id="@+id/bt"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".Main4Activity">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/lv"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="欢迎"
android:layout_centerHorizontal="true"
android:id="@+id/tv"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="进入注册页面"
android:id="@+id/bt"
android:layout_centerInParent="true"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvOne"
android:text="用户名"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tvTwo"
android:text="手机号"
/>
</LinearLayout>