Android: how to create Switch case from this?


Question

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.

1
28
11/19/2010 5:12:39 PM

Accepted Answer

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!

75
7/8/2019 3:41:43 PM

@Override
public void onClick(View v)
{
    switch (v.getId())
    {
        case R.id.:

            break;
        case R.id.:

            break;
        default:
            break;
    }
}

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon