Android Search View не работает

81
7

Панель поиска находится в панели действий. Когда я нажимаю на нее, никаких действий нет.

Activity.java

 public class MainActivity extends AppCompatActivity {
DrawerLayout mDrawerLayout;
NavigationView mNavigationView;
FragmentManager mFragmentManager;
FragmentTransaction mFragmentTransaction;
ImageView profileiamge;
DatabaseReference mDatabase;
private RecyclerView recyclerView1;
SearchAdapter mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

/**
*Setup the DrawerLayout and NavigationView
*/
String username = getIntent().getStringExtra("username");
String imageurl = getIntent().getStringExtra("imageurl");
String email = getIntent().getStringExtra("email");
Log.e("url",imageurl);

mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
mNavigationView = (NavigationView) findViewById(R.id.shitstuff) ;
View header = mNavigationView.getHeaderView(0);
profileiamge=(ImageView)header.findViewById(R.id.imageView5) ;
new DownloadImageTask(profileiamge).execute(imageurl);

/**
* Lets inflate the very first fragment
* Here , we are inflating the TabFragment as the first Fragment
*/

mFragmentManager = getSupportFragmentManager();
mFragmentTransaction = mFragmentManager.beginTransaction();
mFragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
/**
* Setup click events on the Navigation View Items.
*/

mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem menuItem) {
mDrawerLayout.closeDrawers();

if (menuItem.getItemId() == R.id.nav_item_sent) {
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.containerView,new SentFragment()).commit();

}

if (menuItem.getItemId() == R.id.nav_item_inbox) {
FragmentTransaction xfragmentTransaction = mFragmentManager.beginTransaction();
xfragmentTransaction.replace(R.id.containerView,new TabFragment()).commit();
}

return false;
}

});

/**
* Setup Drawer Toggle of the Toolbar
*/

android.support.v7.widget.Toolbar toolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.toolbar);
ActionBarDrawerToggle mDrawerToggle = new ActionBarDrawerToggle(this,mDrawerLayout, toolbar,R.string.app_name,
R.string.app_name);
toolbar.setTitle(" ");
mDrawerLayout.setDrawerListener(mDrawerToggle);

mDrawerToggle.syncState();
mDatabase = FirebaseDatabase.getInstance().getReference();
GeoFire geoFire = new GeoFire(mDatabase.child("Location"));
geoFire.setLocation("firebase-hq1", new GeoLocation(37.7855889, -122.4056973), new GeoFire.CompletionListener() {
@Override
public void onComplete(String key, DatabaseError error) {
if (error != null) {
System.err.println("There was an error saving the location to GeoFire: " + error);
} else {
System.out.println("Location saved on server successfully!");
}
}

});

}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
// getMenuInflater().inflate(R.menu.main, menu);
SearchManager searchManager = (SearchManager)
getSystemService(Context.SEARCH_SERVICE);
MenuItem searchMenuItem = menu.findItem(R.id.action_search);
SearchView searchView = (SearchView) searchMenuItem.getActionView();

searchView.setSearchableInfo(searchManager.
getSearchableInfo(getComponentName()));
searchView.setSubmitButtonEnabled(true);
SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {

@Override
public boolean onQueryTextSubmit(final String query) {
Log.e("Search", "Search");
return false;
}

@Override
public boolean onQueryTextChange(final String newText) {

Log.e("Search", "Search");
DatabaseReference databaseReference1 = mDatabase.child("Coupon");
databaseReference1.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Coupon> couponList = new ArrayList<>();
for (DataSnapshot val : dataSnapshot.getChildren()) {
//I am not sure what record are you specifically looking for
//This is if you are getting the Key which is the record ID for your Coupon Object
if (val.getKey().contains(newText)) {
// count++;
Coupon coupon = new Coupon();
coupon = dataSnapshot.child(val.getKey()).getValue(Coupon.class);
couponList.add(coupon);
}

//This is if your are querying for the hotel child
if (val.child("hotel").getValue(String.class).contains(newText)) {
//Do what you want with the record
}
}
recyclerView1 = (RecyclerView) findViewById(R.id.recycler_view);

// prepareMovieData();
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(MainActivity.this);
recyclerView1.setLayoutManager(mLayoutManager);
recyclerView1.setItemAnimator(new DefaultItemAnimator());
mAdapter = new SearchAdapter(MainActivity.this, couponList);
recyclerView1.setAdapter(mAdapter);
mAdapter.notifyDataSetChanged();
}

@Override
public void onCancelled(DatabaseError databaseError) {

}

});

return true;
}
};
searchView.setOnQueryTextListener(textChangeListener);
return true;

}
}

Я поместил Logs в методы onQueryTextSubmit и onQueryTextChange, но не было журнала logcat.That означает, что Search View не запускается.

main.xml

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:orderInCategory="100"
android:icon="@drawable/search"
android:title="@string/action_settings"
android:layout_centerInParent="true"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.widget.SearchView" />
<item
android:id="@+id/action_alarm"
android:orderInCategory="100"
android:icon="@drawable/alarm"
android:title="@string/action_settings"
app:showAsAction="ifRoom" />
</menu>

Надеюсь, кто-то может помочь мне решить эту проблему. Спасибо заранее.

спросил(а) 2017-04-20T13:05:00+03:00 3 года, 6 месяцев назад
1
Решение
59

Пожалуйста, проверьте эту ссылку на YouTube, Ссылка. Вам нужен этот результат?

ответил(а) 2017-04-20T13:23:00+03:00 3 года, 6 месяцев назад
Ваш ответ
Введите минимум 50 символов
Чтобы , пожалуйста,
Выберите тему жалобы:

Другая проблема