我有一個包含搜索視圖的操作欄。當我想通過單擊搜索按鈕從列表視圖中搜索某些內容時,操作欄顯示左側的後退按鈕。如果單擊此按鈕按鈕獲得搜索列表後,搜索視圖和後退按鈕消失,但列表視圖只顯示該搜索列表不是原始列表。ActionBar後退按鈕不起作用
public class ActivityThree extends AppCompatActivity{
FloatingActionButton fab;
DBHelper myDb;
ArrayList<AccountDetails> rList;
ListView listView;
RemainderAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_three);
fab = (FloatingActionButton) findViewById(R.id.fab);
listView = (ListView) findViewById(R.id.listView);
myDb = new DBHelper(this);
showViews();
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(ActivityThree.this, ActivityFour.class));
}
});
}
private void showViews() {
rList = new ArrayList<AccountDetails>();
rList = myDb.getAllRows();
if (rList.size() != 0) {
adapter = new RemainderAdapter(this, rList);
listView.setAdapter(adapter);
listView.setTextFilterEnabled(true);
} else {
Toast.makeText(this,"There is no item in the list",Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
getMenuInflater().inflate(R.menu.menu_item,menu);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(false);
SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener()
{
@Override
public boolean onQueryTextChange(String newText)
{
adapter.getFilter().filter(newText);
return true;
}
@Override
public boolean onQueryTextSubmit(String query)
{
adapter.getFilter().filter(query);
invalidateOptionsMenu();
return true;
}
};
searchView.setOnQueryTextListener(textChangeListener);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id==R.id.changePwd){
startActivity(new Intent(this, PwdChange.class));
return true;
}
if(id==R.id.about){
startActivity(new Intent(this, ActivityAbout.class));
return true;
}if(id==R.id.share){
try
{ Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "ABCD");
String sAux = "\nLet me recommend you this application\n\n";
i.putExtra(Intent.EXTRA_TEXT, sAux);
startActivity(Intent.createChooser(i, "Choose any one"));
}
catch(Exception e)
{
}
}
if(id==R.id.exit){
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
}
return super.onOptionsItemSelected(item);
}
}
如何通過單擊此返回按鈕來獲取原始列表?先謝謝 – diya
再次設置listadapter。 –
歡迎使用stackoverflow!發佈你的代碼。 –