Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ...
- public class MainActivity extends AppCompatActivity {
- ...
- @Override
- protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- ...
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.menu_main, menu);
- //khusus proses search
- MenuItem item = menu.findItem(R.id.cari);
- SearchView searchView = (SearchView) item.getActionView();
- searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
- @Override
- public boolean onQueryTextSubmit(String s) { //ketika tekan enter
- Toast.makeText(getApplicationContext(), s, Toast.LENGTH_SHORT).show();
- return false;
- }
- @Override
- public boolean onQueryTextChange(String s) { //ketika text berubah
- return false;
- }
- });
- return super.onCreateOptionsMenu(menu);
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.tambah:
- View view = findViewById(R.id.main_layout_id); //layout main activity harus constraint
- String message = "Snackbar action Tambah";
- int duration = Snackbar.LENGTH_SHORT; //alt + enter pada "Snackbar" untuk mendownload dependency
- Snackbar.make(view, message, duration).show();
- return true;
- case R.id.selip:
- Toast.makeText(getApplicationContext(), "action Selip", Toast.LENGTH_SHORT).show();
- return true;
- case R.id.auto_update:
- Toast.makeText(getApplicationContext(), "action Update", Toast.LENGTH_SHORT).show();
- return true;
- default:
- return super.onOptionsItemSelected(item);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement