lawang code

lawang Code


Tanyakan kode disini

Bagaimana cara agar tiap item pada Pencarian listview jika di klik akan intent ke activitiy baru

ditanyakan oleh Muhammad Ihsan 2 tahun yang lalu

bagaimana caranya agar tiap item pada pencarian di listview ketika di klik maka akan inten ke activity baru, misalnya saya klik item1 maka akan tampil activity1, klik item 2 maka akan tampil activity 2,

enter code here public class MainActivity extends AppCompatActivity {

ListView lv; SearchView sv; String[] teams={

"Alfred", "Beth", "Bill",

}; ArrayAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lv=(ListView) findViewById(R.id.listView_Data);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);

if(getSupportActionBar()!=null){ getSupportActionBar().setElevation(5); }

sv=(SearchView) findViewById(R.id.menu_search); adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,teams); lv.setAdapter(adapter);

lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) { String itemValue = (String) lv.getItemAtPosition(position); int itemPosition = position; // Show Alert Toast.makeText(getApplicationContext(), "Position :"+itemPosition+" ListItem : " +itemValue , Toast.LENGTH_LONG).show();

switch( itemValue ) { case "alfred": Intent alfred = new Intent(MainActivity.this, Main2Activity.class); startActivity(alfred); break;

case "beth": Intent beth = new Intent(MainActivity.this, Main3Activity.class); startActivity(beth); break; case "bill": Intent bill = new Intent(MainActivity.this, MainActivity4.class); startActivity(bill); break;

} } });

}

@Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.menu, menu);

MenuItem searchItem = menu.findItem(R.id.menu_search);

SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { adapter.getFilter().filter(query); return false; }

@Override public boolean onQueryTextChange(String newText) { adapter.getFilter().filter(newText); return false; } });

return true; } }

Anda harus login terlebih dahulu untuk memberikan komentar

Recent Tag

X 6
X 48
X 14
X 10
X 1
X 5
X 4
X 18
X 10

Bantuan

Help

Feedback

Help