Я создал следующий виджет Android:
Спиннер "Location", заполняемый из таблицы sqlite "Location", который при длительном касании открывает диалоговое окно EditText и сохраняет значение EditText 'valie дляТаблица «Расположение», при закрытии всплывающего диалогового окна.
Теперь я хотел бы, чтобы счетчик автоматически обновлял себя с помощью только что введенной мной информации, и не знаю, как действовать - вот мой текущий код
chooseLocation = (Spinner) this.findViewById(R.id.choose_location);
//set long clicks to add an item
chooseLocation.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
//just an EditText dialog
AlertDialog.Builder builder = new AlertDialog.Builder(MyActivity.this);
final EditText input = new EditText(MyActivity.this);
builder.setView(input);
builder.setMessage(R.string.add_location)
.setCancelable(false)
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
if (input.getText().toString().equals("") == false) {
//save EditText to database
db.open();
db.insertLocation(input.getText().toString());
db.close();
}
dialog.cancel();
}})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}})
.show();
return true;
}});
//Binding the database data and the spinner
Cursor locations = db.getLocations();
startManagingCursor(locations);
SimpleCursorAdapter adapter1 = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, locations,
new String[] { "_name"}, new int[] { android.R.id.text1});
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
chooseLocation.setAdapter(adapter1);
mb.close();