我製作了以下Android部件:Android:Spinner autorefreshing本身 - 如何?
從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();
我試了兩次,並沒有取得成功。我最終在activity上調用了Create()方法,因爲我有5個spinners,其中4個更新對方,並且活動中沒有其他任何東西。一種大錘解決方案,仍然會更好。 – Pouzzler 2011-05-25 08:12:53