Just cleaning the code and adding some function (like reset the form)
This commit is contained in:
parent
80a0223d9a
commit
7e869e0837
@ -5,6 +5,7 @@
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="testRunner" value="PLATFORM" />
|
||||
<option name="disableWrapperSourceDistributionNotification" value="true" />
|
||||
<option name="distributionType" value="DEFAULT_WRAPPED" />
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="gradleJvm" value="1.8" />
|
||||
|
||||
@ -2,41 +2,55 @@ package fr.romanet.vj.apps.myweather;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import fr.romanet.vj.apps.myweather.bo.City;
|
||||
import fr.romanet.vj.apps.myweather.repository.CityRepository;
|
||||
|
||||
public class AddCity extends AppCompatActivity {
|
||||
|
||||
private EditText cityName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.add_city_page);
|
||||
|
||||
Toolbar toolbarAddCity = (Toolbar) findViewById(R.id.toolbarAddCity);
|
||||
setSupportActionBar(toolbarAddCity);
|
||||
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
|
||||
Button button = (Button) findViewById(R.id.btnSaveCity);
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
public void onClick(View v) {
|
||||
EditText editTextnewCity = (EditText) findViewById(R.id.editTextNewCity);
|
||||
String newCity = (String) editTextnewCity.getText().toString();
|
||||
if(editTextnewCity.length() == 0)
|
||||
button.setOnClickListener(new View.OnClickListener()
|
||||
{
|
||||
editTextnewCity.setError("Please, enter a city name");
|
||||
public void onClick(View v)
|
||||
{
|
||||
cityName = (EditText) findViewById(R.id.editTextNewCity);
|
||||
final String newCityString = cityName.getEditableText().toString();
|
||||
if(newCityString.length() == 0)
|
||||
{
|
||||
cityName.setError("Please, enter a city name");
|
||||
}
|
||||
else
|
||||
System.out.println(newCity);
|
||||
//Ajoute la ville a une base de données
|
||||
//Prélève le texte avec le get
|
||||
//S'il est vide on l'alert et on fais rien
|
||||
//Sinon écran d'accueil qui change
|
||||
saveCity(newCityString);
|
||||
resetForm();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void resetForm()
|
||||
{
|
||||
cityName.setText(null);
|
||||
}
|
||||
|
||||
private void saveCity(String cityName)
|
||||
{
|
||||
CityRepository.getInstance(this).addCity(new City(cityName));
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user