Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: how to create Switch case from this?

Tags:

java

android

public void onItemClick(AdapterView<?> a, View v, int position, long id) {     AlertDialog.Builder adb = new AlertDialog.Builder(CategoriesTab.this);      adb.setTitle("Selected Category");     adb.setMessage("Selected Item is = "+lv1.getItemAtPosition(position));     adb.setPositiveButton("Ok", null);     adb.show(); } 

This at the moment displays an alertbox when an item from listview is clicked. I want to convert the alertbox to load a specific xml for each choices clicked. How can i do this? thanks for your help.

like image 787
Riza Avatar asked Nov 19 '10 17:11

Riza


People also ask

How do you use a switch statement in Kotlin?

Kotlin does not provide an option to write a switch-case statement; however we can implement the switch-case functionality in Kotlin using the when() function which works exactly the same way switch works in other programming languages.

How do you use a switch case method?

The switch case in java is used to select one of many code blocks for execution. Break keyword: As java reaches a break keyword, the control breaks out of the switch block. The execution of code stops on encountering this keyword, and the case testing inside the block ends as the match is found.

Can a switch case have multiple lines of code?

Yes. When the code enters a case block, it'll continue executing all commands until it reaches the break or say a return statement.


2 Answers

switch(position) {     case 0:         setContentView(R.layout.xml0);         break;     case 1:         setContentView(R.layout.xml1);         break;     default:         setContentView(R.layout.default);         break; } 

i hope this will do the job!

like image 172
Ads Avatar answered Sep 30 '22 21:09

Ads


@Override public void onClick(View v) {     switch (v.getId())     {         case R.id.:              break;         case R.id.:              break;         default:             break;     } } 
like image 30
Deepak Rawat Avatar answered Sep 30 '22 21:09

Deepak Rawat