更新
这是我的列表视图应用程序:
我单击启动意图并加载我的电子邮件活动的电子邮件选项:
如果用户单击“返回”,则列表视图为空白:
这是我设置列表视图的方法:
public class view extends ListActivity {
ImageButton searchButton;
EditText searchName;
ListView searchedListResults;
long idToPass;
String numReturned;
String email;
SimpleCursorAdapter cursorAdapter;
DBHandler getCons;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.search);
searchedListResults = (ListView) findViewById(android.R.id.list);
list();
searchName = (EditText) findViewById(R.id.inputName);
searchedListResults.setTextFilterEnabled(true);
searchName.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
cursorAdapter.getFilter().filter(s.toString());
searchedListResults.refreshDrawableState();
}
});
getCons = new DBHandler(this, null, null);
cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
getCons.open();
return getCons.getChanges(constraint.toString());
}
});
searchedListResults.setAdapter(cursorAdapter);
}
private void list() {
DBHandler DBsearchRef = new DBHandler(this, null, null);
DBHandler search = new DBHandler(this, null, null);
search.open();
Cursor cursor = search.getData();
search.close();
startManagingCursor(cursor);
String[] from = new String[] { DBsearchRef.KEY_NAME,
DBsearchRef.KEY_TEL, DBsearchRef.KEY_EMAIL,
DBsearchRef.KEY_COMMENTS };
int[] to = new int[] { R.id.txtNameSet, R.id.txtContactSet,
R.id.txtEmailSet, R.id.txtCommentSet };
cursorAdapter = new SimpleCursorAdapter(this, R.layout.searchagain,
cursor, from, to);
searchedListResults.setAdapter(cursorAdapter);
}
@Override
protected void onResume() {
super.onResume();
list();
searchName = (EditText) findViewById(R.id.inputName);
searchedListResults.setTextFilterEnabled(true);
searchName.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable s) {
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
cursorAdapter.getFilter().filter(s.toString());
searchedListResults.refreshDrawableState();
}
});
getCons = new DBHandler(this, null, null);
cursorAdapter.setFilterQueryProvider(new FilterQueryProvider() {
public Cursor runQuery(CharSequence constraint) {
getCons.open();
return getCons.getChanges(constraint.toString());
}
});
searchedListResults.setAdapter(cursorAdapter);
}
@Override
public void onListItemClick(ListView list, View v, int list_posistion,
long item_id) {
idToPass = item_id;
idToPass = item_id;
DBHandler num = new DBHandler(this, null, null);
num.open();
numReturned = num.getNum(idToPass);
email = num.getEmail(idToPass);
num.close();
final CharSequence[] items = { "Call Contact", "Email Contact",
"Edit Contact", "Add Appointment" };
Builder alertDialogBuilder = new AlertDialog.Builder(view.this);
alertDialogBuilder.setTitle("Contact Options:");
alertDialogBuilder.setItems(items,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (items[item].equals("Call Contact")) {
Intent makeCall = new Intent(Intent.ACTION_DIAL,
Uri.parse("tel:" + numReturned));
startActivity(makeCall);
}
else if (items[item].equals("Email Contact")) {
Intent emailIntent = new Intent(
"com.example.flybaseapp.ContactsEmail");
emailIntent.putExtra("passedEmailAdd", email);
startActivity(emailIntent);
} else if (items[item].equals("Edit Contact")) {
Intent Edit = new Intent(
"com.example.flybaseapp.viewEdit");
Edit.putExtra("passedID", idToPass);
startActivity(Edit);
}
else if (items[item].equals("Add Appointment")) {
Intent conAdd = new Intent(
"com.example.flybaseapp.AddAppointmentContact");
conAdd.putExtra("newpassedID", idToPass);
startActivity(conAdd);
}
}
});
alertDialogBuilder.show();
}
是否在覆盖的 onResume 方法中设置它?