Base Terminada
This commit is contained in:
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -4,6 +4,7 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -13,37 +14,27 @@ public class AddUserActivity extends AppCompatActivity {
|
||||
private DatabaseHelper databaseHelper;
|
||||
|
||||
private Button grabarButton;
|
||||
private Button verButton;
|
||||
private EditText nombreText;
|
||||
private EditText hobbyText;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
setContentView(R.layout.activity_add_user);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
|
||||
databaseHelper = new DatabaseHelper(this);
|
||||
|
||||
grabarButton = findViewById(R.id.grabarButton);
|
||||
verButton = findViewById(R.id.verButton);
|
||||
nombreText = findViewById(R.id.nombreText);
|
||||
hobbyText = findViewById(R.id.hobbyText);
|
||||
|
||||
grabarButton.setOnClickListener(onSave());
|
||||
verButton.setOnClickListener(onShow());
|
||||
}
|
||||
|
||||
private View.OnClickListener onShow() {
|
||||
return new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(AddUserActivity.this, GetAllUsersActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private View.OnClickListener onSave() {
|
||||
return new View.OnClickListener(){
|
||||
return new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
databaseHelper.addUserDetail(
|
||||
nombreText.getText().toString(),
|
||||
@@ -56,7 +47,16 @@ public class AddUserActivity extends AppCompatActivity {
|
||||
"Datos grabados!",
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
finish();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,11 +13,16 @@ public class CustomAdapter extends BaseAdapter {
|
||||
|
||||
private Context context;
|
||||
private List<User> users;
|
||||
|
||||
public CustomAdapter(Context context, List<User> users) {
|
||||
this.context = context;
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
public void changeList(List<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return users.size();
|
||||
|
||||
@@ -12,12 +12,14 @@ import androidx.appcompat.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.ListView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GetAllUsersActivity extends AppCompatActivity {
|
||||
private ListView listView;
|
||||
private Button agregarButton;
|
||||
private List<User> users;
|
||||
private CustomAdapter customAdapter;
|
||||
private DatabaseHelper databaseHelper;
|
||||
@@ -28,6 +30,8 @@ public class GetAllUsersActivity extends AppCompatActivity {
|
||||
setContentView(R.layout.activity_get_all_users);
|
||||
|
||||
listView = findViewById(R.id.listView);
|
||||
agregarButton = findViewById(R.id.agregarButton);
|
||||
|
||||
databaseHelper = new DatabaseHelper(this);
|
||||
users = databaseHelper.getAllUsers();
|
||||
customAdapter = new CustomAdapter(this, users);
|
||||
@@ -41,5 +45,21 @@ public class GetAllUsersActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
agregarButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(GetAllUsersActivity.this, AddUserActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
users = databaseHelper.getAllUsers();
|
||||
customAdapter.changeList(users);
|
||||
customAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
@@ -24,6 +25,8 @@ public class UpdateDeleteActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_update_delete);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
|
||||
user = (User) getIntent().getSerializableExtra("user");
|
||||
databaseHelper = new DatabaseHelper(this);
|
||||
@@ -44,7 +47,7 @@ public class UpdateDeleteActivity extends AppCompatActivity {
|
||||
return new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
new AlertDialog.Builder(UpdateDeleteActivity.this)
|
||||
new AlertDialog.Builder(UpdateDeleteActivity.this)
|
||||
.setMessage("Estas seguro?")
|
||||
.setPositiveButton("Si", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
@@ -55,16 +58,11 @@ public class UpdateDeleteActivity extends AppCompatActivity {
|
||||
"Usuario eliminado correctamente",
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
|
||||
Intent intent = new Intent(UpdateDeleteActivity.this, AddUserActivity.class);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
|
||||
startActivity(intent);
|
||||
finish();
|
||||
}
|
||||
})
|
||||
.setNegativeButton("No", null)
|
||||
.show();
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -104,4 +102,11 @@ public class UpdateDeleteActivity extends AppCompatActivity {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
finish();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,18 +47,4 @@
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/hobbyText" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/verButton"
|
||||
style="@android:style/Widget.Material.Button.Colored"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:text="Ver Datos"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/grabarButton" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -15,7 +15,7 @@
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/button3"
|
||||
app:layout_constraintBottom_toTopOf="@+id/agregarButton"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
@@ -23,13 +23,13 @@
|
||||
</ListView>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:id="@+id/agregarButton"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="Button"
|
||||
android:text="Agregar"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
Reference in New Issue
Block a user