Compare commits
3 Commits
39779040ad
...
88101f58ca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
88101f58ca | ||
|
|
fe7a018cf4 | ||
|
|
fdd80aa3a5 |
@ -1,9 +1,19 @@
|
||||
package fr.romanet.vj.apps.myweather;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.romanet.vj.apps.myweather.bo.City;
|
||||
import fr.romanet.vj.apps.myweather.repository.CityRepository;
|
||||
|
||||
public class ShowTemparature extends AppCompatActivity {
|
||||
|
||||
@ -23,4 +33,36 @@ public class ShowTemparature extends AppCompatActivity {
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_items, menu);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(@NonNull MenuItem item)
|
||||
{
|
||||
//We handle the click on a menu item
|
||||
if (item.getItemId() == R.id.item_delete)
|
||||
{
|
||||
cityToDelete();
|
||||
Intent intent = new Intent(ShowTemparature.this, MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void cityToDelete()
|
||||
{
|
||||
final List<City> city = CityRepository.getInstance(this).getCity();
|
||||
for(int i = 0; i < city.size(); i++)
|
||||
{
|
||||
if(city.get(i).nameCity.equals(currentCityName))
|
||||
{
|
||||
CityRepository.getInstance(this).deleteCity(city.get(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
9
app/src/main/res/menu/menu_items.xml
Normal file
9
app/src/main/res/menu/menu_items.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/item_delete"
|
||||
android:title="@string/deleteItem"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
@ -13,5 +13,6 @@
|
||||
<string name="title_activity_test_constraint_layout">TestConstraintLayout</string>
|
||||
|
||||
<string name="firstAction">Please click on the Add button in order to add a city</string>
|
||||
<string name="deleteItem">Delete</string>
|
||||
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user