我想在 android 中使用 Tabs(ViewPager Indicator) 实现无限 ViewPager。
我发现了很多示例项目,所有这些都只包含 ViewPager。我需要将无限 ViewPager 与选项卡集成。
我发现的一些样本:
1.) https://github.com/antonyt/InfiniteViewPager
任何帮助或想法将不胜感激。
我想在 android 中使用 Tabs(ViewPager Indicator) 实现无限 ViewPager。
我发现了很多示例项目,所有这些都只包含 ViewPager。我需要将无限 ViewPager 与选项卡集成。
我发现的一些样本:
1.) https://github.com/antonyt/InfiniteViewPager
任何帮助或想法将不胜感激。
* SQLITE DATA BASE WITH GOOGLE MAP *
GOOGLE MAP
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.gms:play-services-maps:11.8.0'
implementation 'com.github.pedroSG94:AutoPermissions:1.0.3'
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<meta-data
android:name="@string/permissions_loader_meta_key"
android:value="android.permission.WRITE_EXTERNAL_STORAGE, android.permission.CAMERA,android.permission.ACCESS_FINE_LOCATION,android.permission.ACCESS_COARSE_LOCATION" />
<fragment android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
public class DashboardActivity extends AppCompatActivity implements OnMapReadyCallback, AutoPermissionsListener ,GoogleMap.OnInfoWindowClickListener {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
AutoPermissions.Companion.loadActivityPermissions(DashboardActivity.this, 1);
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
AutoPermissions.Companion.parsePermissions(DashboardActivity.this, requestCode, permissions, this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
LatLng sydney = new LatLng(23.076427, 72.538418);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in India"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
@Override
public void onDenied(int i, String[] strings) {
}
@Override
public void onGranted(int i, String[] strings) {
}
@Override
public void onInfoWindowClick(Marker marker) {
mMap.setInfoWindowAdapter(new MarkerInfoWindowAdapter());
}
//
public class MarkerInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
public void MarkerInfoWindowAdapter() {
}
@Override
public View getInfoWindow(Marker marker) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
View v = getLayoutInflater().inflate(R.layout.popup_vendor_info_new, null);
TextView txtProviderName = (TextView) v.findViewById(R.id.txtProviderName);
TextView txtDistance = (TextView) v.findViewById(R.id.txtDistance);
String getMySnippet[] = marker.getSnippet().split(",");
txtProviderName.setText(marker.getTitle());
txtDistance.setText(getMySnippet[0]);
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(DashboardActivity.this, "CLICKED", Toast.LENGTH_SHORT).show();
}
});
return v;
}
}
}
SQLITE
public class Constants {
public static final int ADD_RECORD = 0;
public static final int UPDATE_RECORD = 1;
public static final String DML_TYPE = "DML_TYPE";
public static final String UPDATE = "Update";
public static final String INSERT = "Insert";
public static final String DELETE = "Delete";
public static final String FIRST_NAME = "Firstname";
public static final String LAST_NAME = "Lastname";
public static final String ID = "ID";
}
public class ContactModel {
private String ID;
private String firstName;
private String lastName;
private String email;
private String phone;
private String password;
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getID() {
return ID;
}
public void setID(String ID) {
this.ID = ID;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
/**
* Created by Sanjay on 27-08-2015.
*/
public class SQLiteHelper extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "I-verve.db";
public static final String TABLE_NAME = "users";
public static final String COLUMN_ID = "ID";
public static final String COLUMN_FIRST_NAME = "FIRST_NAME";
public static final String COLUMN_LAST_NAME = "LAST_NAME";
public static final String COLUMN_EMAIl = "COLUMN_EMAIl";
public static final String COLUMN__PHONE = "COLUMN__PHONE";
public static final String COLUMN__PASSWORD = "COLUMN__PASSWORD";
private SQLiteDatabase database;
public SQLiteHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db)
{
db.execSQL("create table " + TABLE_NAME + " ( " + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," + COLUMN_FIRST_NAME + " VARCHAR, " + COLUMN_LAST_NAME + " VARCHAR, " + COLUMN_EMAIl + " VARCHAR , " + COLUMN__PHONE + " VARCHAR, "+COLUMN__PASSWORD + " VARCHAR);");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public void insertRecord(ContactModel contact) {
database = this.getReadableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_FIRST_NAME, contact.getFirstName());
contentValues.put(COLUMN_LAST_NAME, contact.getLastName());
contentValues.put(COLUMN_EMAIl, contact.getEmail());
contentValues.put(COLUMN__PHONE, contact.getPhone());
contentValues.put(COLUMN__PASSWORD, contact.getPassword());
database.insert(TABLE_NAME, null, contentValues);
database.close();
}
public void insertRecordAlternate(ContactModel contact) {
database = this.getReadableDatabase();
database.execSQL("INSERT INTO " + TABLE_NAME + "(" + COLUMN_FIRST_NAME + "," + COLUMN_LAST_NAME + ") VALUES('" + contact.getFirstName() + "','" + contact.getLastName() + "')");
database.close();
}
public ArrayList<ContactModel> getAllRecords() {
database = this.getReadableDatabase();
Cursor cursor = database.query(TABLE_NAME, null, null, null, null, null, null);
ArrayList<ContactModel> contacts = new ArrayList<ContactModel>();
ContactModel contactModel;
if (cursor.getCount() > 0) {
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
contactModel = new ContactModel();
contactModel.setID(cursor.getString(0));
contactModel.setFirstName(cursor.getString(1));
contactModel.setLastName(cursor.getString(2));
contactModel.setEmail(cursor.getString(3));
contactModel.setPhone(cursor.getString(4));
contactModel.setPassword(cursor.getString(5));
contacts.add(contactModel);
}
}
cursor.close();
database.close();
return contacts;
}
public ArrayList<ContactModel> getAllRecordsAlternate() {
database = this.getReadableDatabase();
Cursor cursor = database.rawQuery("SELECT * FROM " + TABLE_NAME, null);
ArrayList<ContactModel> contacts = new ArrayList<ContactModel>();
ContactModel contactModel;
if (cursor.getCount() > 0) {
for (int i = 0; i < cursor.getCount(); i++) {
cursor.moveToNext();
contactModel = new ContactModel();
contactModel.setID(cursor.getString(0));
contactModel.setFirstName(cursor.getString(1));
contactModel.setLastName(cursor.getString(2));
contactModel.setEmail(cursor.getString(3));
contactModel.setPhone(cursor.getString(4));
contactModel.setPassword(cursor.getString(5));
contacts.add(contactModel);
}
}
cursor.close();
database.close();
return contacts;
}
public void updateRecord(ContactModel contact) {
database = this.getReadableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(COLUMN_FIRST_NAME, contact.getFirstName());
contentValues.put(COLUMN_LAST_NAME, contact.getLastName());
database.update(TABLE_NAME, contentValues, COLUMN_ID + " = ?", new String[]{contact.getID()});
database.close();
}
public void updateRecordAlternate(ContactModel contact) {
database = this.getReadableDatabase();
database.execSQL("update " + TABLE_NAME + " set " + COLUMN_FIRST_NAME + " = '" + contact.getFirstName() + "', " + COLUMN_LAST_NAME + " = '" + contact.getLastName() + "' where " + COLUMN_ID + " = '" + contact.getID() + "'");
database.close();
}
public void deleteAllRecords() {
database = this.getReadableDatabase();
database.delete(TABLE_NAME, null, null);
database.close();
}
public void deleteAllRecordsAlternate() {
database = this.getReadableDatabase();
database.execSQL("delete from " + TABLE_NAME);
database.close();
}
public void deleteRecord(ContactModel contact) {
database = this.getReadableDatabase();
database.delete(TABLE_NAME, COLUMN_ID + " = ?", new String[]{contact.getID()});
database.close();
}
public void deleteRecordAlternate(ContactModel contact) {
database = this.getReadableDatabase();
database.execSQL("delete from " + TABLE_NAME + " where " + COLUMN_ID + " = '" + contact.getID() + "'");
database.close();
}
public ArrayList<String> getAllTableName()
{
database = this.getReadableDatabase();
ArrayList<String> allTableNames=new ArrayList<String>();
Cursor cursor=database.rawQuery("SELECT name FROM sqlite_master WHERE type='table'",null);
if(cursor.getCount()>0)
{
for(int i=0;i<cursor.getCount();i++)
{
cursor.moveToNext();
allTableNames.add(cursor.getString(cursor.getColumnIndex("name")));
}
}
cursor.close();
database.close();
return allTableNames;
}
public boolean checkUserExist(String username, String password)
{
database = this.getReadableDatabase();
String[] columns = {COLUMN_EMAIl};
String selection = COLUMN_EMAIl+"=? and "+ COLUMN__PASSWORD+" = ?";
String[] selectionArgs = {username, password};
Cursor cursor = database.query(TABLE_NAME, columns, selection, selectionArgs, null, null, null);
int count = cursor.getCount();
cursor.close();
close();
database.close();
if(count > 0){
return true;
} else {
return false;
}
}
}
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class RegisterActivity extends AppCompatActivity {
public TextView txt_login;
public Button btn_Submit;
SQLiteHelper sQLiteHelper;
EditText edit_Fname,edit_Lname,edit_Email,edit_Phone,edit_Password;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
sQLiteHelper = new SQLiteHelper(RegisterActivity.this);
txt_login=findViewById(R.id.txt_login);
btn_Submit=findViewById(R.id.btn_Submit);
edit_Fname=findViewById(R.id.edit_Fname);
edit_Lname=findViewById(R.id.edit_Lname);
edit_Email=findViewById(R.id.edit_Email);
edit_Phone=findViewById(R.id.edit_Phone);
edit_Password=findViewById(R.id.edit_Password);
btn_Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
if(edit_Fname.getText().toString().isEmpty())
{
edit_Fname.requestFocus();
edit_Fname.setError("Please enter fname");
}
else if(edit_Lname.getText().toString().isEmpty())
{
edit_Lname.requestFocus();
edit_Lname.setError("Please enter lname");
}
else if(edit_Email.getText().toString().isEmpty())
{
edit_Email.requestFocus();
edit_Email.setError("Please enter email");
}
else if(edit_Phone.getText().toString().isEmpty())
{
edit_Phone.requestFocus();
edit_Phone.setError("Please enter phone");
}
else if(edit_Password.getText().toString().isEmpty())
{
edit_Password.requestFocus();
edit_Password.setError("Please enter password");
}
else {
ContactModel contact = new ContactModel();
contact.setFirstName(edit_Fname.getText().toString());
contact.setLastName(edit_Lname.getText().toString());
contact.setEmail(edit_Email.getText().toString());
contact.setPhone(edit_Phone.getText().toString());
contact.setPassword(edit_Password.getText().toString());
sQLiteHelper.insertRecord(contact);
Toast.makeText(RegisterActivity.this, "Record Inserted Success", Toast.LENGTH_SHORT).show();
edit_Fname.setText("");
edit_Lname.setText("");
edit_Email.setText("");
edit_Phone.setText("");
edit_Password.setText("");
finish();
}
}
});
}
public class LoginActivity extends AppCompatActivity {
public EditText edit_Email,edit_Password;
public Button btn_Login;
public TextView txt_createNewAccount;
SQLiteHelper sQLiteHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
sQLiteHelper = new SQLiteHelper(LoginActivity.this);
edit_Email=findViewById(R.id.edit_Email);
edit_Password=findViewById(R.id.edit_Password);
btn_Login=findViewById(R.id.btn_Login);
txt_createNewAccount=findViewById(R.id.txt_createNewAccount);
btn_Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
boolean isExist = sQLiteHelper.checkUserExist(edit_Email.getText().toString(), edit_Password.getText().toString());
if(isExist)
{
startActivity(new Intent(LoginActivity.this,DashboardActivity.class));
} else {
edit_Password.setText(null);
Toast.makeText(LoginActivity.this, "Login failed. Invalid username or password.", Toast.LENGTH_SHORT).show();
}
}
});
}
**viewpager with indicator in android using fragment**
ViewPagerAdapter
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
public class ViewPagerAdapter extends FragmentPagerAdapter {
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public int getCount() {
return 4;
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
FragmentAnimation1 fragmentAnimation1 = new FragmentAnimation1();
return fragmentAnimation1;
case 1:
FragmentAnimation2 fragmentAnimation2 = new FragmentAnimation2();
return fragmentAnimation2;
case 2:
FragmentAnimation3 fragmentAnimation3 = new FragmentAnimation3();
return fragmentAnimation3;
case 3:
FragmentAnimation4 fragmentAnimation4 = new FragmentAnimation4();
return fragmentAnimation4;
}
return null;
}
}
**Activity**
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
viewPager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
xml
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>