Как получить SearchView на ActionBar с логотипом поиска. Эта строка вызывает ошибку DBList item = (DBList) getListAdapter (). GetItem (position);ошибка: не удается найти метод символа setListAdapter (ArrayAdapter)
public class ShowDbList extends AppCompatActivity {
JSONArray valArray;
Thread thread;
ConnectToWebService cw;
private ProgressDialog dialog;
JSONObject jsonObjectPunchInData;
GetPermission objGetPermissions = null;
SearchView searchView;
ProgressDialog dialog1;
String username;
String PunchedInDatabase;
ArrayAdapter<DBList> dbName;
final private int MY_PERMISSIONS_REQUEST_READ_CONTACTS = 2909;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startService(new Intent(this,BackgroundService.class));
BugSenseHandler.initAndStartSession(this, "8104fb89");
Mint.initAndStartSession(this, "131a0997");
setContentView(R.layout.dblist);
cw = new ConnectToWebService(ShowDbList.this);
Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
setActionBar(toolbar);
getActionBar().setTitle("Databases");
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.search, menu);
final MenuItem item = menu.findItem(R.id.action_search);
searchView = (SearchView) item.getActionView();
SearchManager searchManager = (SearchManager) ShowDbList.this.getSystemService(Context.SEARCH_SERVICE);
getMenuInflater().inflate(R.menu.logoutbutton, menu);
SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
menu.findItem(R.id.action_search).collapseActionView();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
if (dbName != null)
dbName.getFilter().filter(newText);
return true;
}
};
return super.onCreateOptionsMenu(menu);
}
private void getPreferences(String statusPreferences) {
// TODO Auto-generated method stub
try {
JSONObject jsonPreferences = new JSONObject(statusPreferences);
Preferences.saveIntegerPreferences(this, "COLLECTION_PICTURES",
jsonPreferences.getInt("COLLECTION_PICTURES"));
Preferences.saveStringPreferences(this, "THEME_CARRYOVER", jsonPreferences.getString("THEME_CARRYOVER"));
} catch (JSONException e) {
Toast.makeText(this,
"Network Connection is too slow please try later",
Toast.LENGTH_SHORT).show();
return;
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.logoutbutton:
Intent logout = new Intent(getApplicationContext(),
LoginActivity.class);
logout.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(logout);
break;
case R.id.action_punchin:
if ((item.getIcon().getConstantState().equals(getResources()
.getDrawable(R.drawable.red).getConstantState())))
item.setIcon(getResources().getDrawable(R.drawable.green));
else
item.setIcon(getResources().getDrawable(R.drawable.red));
break;
}
return true;
}
@Override
protected void onResume() {
super.onResume();
if (cw == null)
cw = new ConnectToWebService(ShowDbList.this);
new AsyncLogout(this).execute();
}
@Override
protected void onStart() {
super.onStart();
FillDatabaseList();
}
protected void onListItemClick(ListView l, View v, int position, long id) {
DBList item = (DBList) getListAdapter().getItem(position);
String dbName = item.DatabaseName;
String DBType= item.DBType;
Integer userId = Integer.parseInt(item.UserID);// Integer.parseInt(valArray.getJSONObject(position)
StringBuilder urlString = new StringBuilder();
urlString.append("UserID=");
urlString.append(userId);
urlString.append("&DbName=");
urlString.append(dbName);
getMethod gmPreferences = getMethod.GetPreferences;
String urlPreferences = cw.getUrl(urlString.toString(), gmPreferences);
urlPreferences = urlPreferences.replaceAll(" ", "%20");
new AsyncGetPreferences().execute(urlPreferences);
getMethod gd = getMethod.GetPermissionsByUserID;
String url = cw.getUrl(urlString.toString(), gd);
url = url.replaceAll(" ", "%20");
new AsyncGetPermissions().execute(url);
Preferences.saveStringPreferences(ShowDbList.this, "DataBaseName",
dbName);
Preferences.saveStringPreferences(ShowDbList.this, "DatabaseType", DBType);
Preferences.saveStringPreferences(ShowDbList.this, "DisplayName",
item.DisplayName);
Preferences.saveStringPreferences(ShowDbList.this, "MobileAdmin",
item.MobileAdmin);
Preferences.saveIntegerPreferences(ShowDbList.this, "UserId", userId);
}
private boolean hasPermission(String string) {
// TODO Auto-generated method stub
return false;
}
private void dismissProgressDialog() {
if (dialog != null && dialog.isShowing()) {
dialog.dismiss();
}
}
@Override
protected void onDestroy() {
dismissProgressDialog();
super.onDestroy();
}
private void FillDatabaseList() {
try {
JSONObject jsonObj = new JSONObject(
Preferences.getStringPreferences(ShowDbList.this, "DBLIST"));
valArray = jsonObj.getJSONArray("DbList");
} catch (JSONException e1) {
e1.printStackTrace();
BugSenseHandler.sendException(e1);
}
// List<DBList> output = new ArrayList<DBList>();
dbName = new ArrayAdapter<DBList>(this, R.layout.dblist_item);
for (Integer i = 0; i < valArray.length(); i++) {
try {
String objDbName = valArray.getJSONObject(i)
.getString("DataBaseName");
String DBType=valArray.getJSONObject(i)
.getString("DatabaseType");
String objDisplayName = valArray.getJSONObject(i)
.getString("DisplayName");
String objUserId = valArray.getJSONObject(i)
.getString("UserID");
String objMobileAdmin = valArray.getJSONObject(i)
.getString("MobileAdmin");
DBList d = new DBList();
d.DatabaseName = objDbName;
d.DBType = DBType;
d.DisplayName = objDisplayName;
d.UserID = objUserId;
d.MobileAdmin = objMobileAdmin;
dbName.add(d);
} catch (JSONException e) {
}
}
setListAdapter(dbName);
}