How to build string for opening new activity

Go To StackoverFlow.com

0

I am trying to make a simple program that could open a new activity when tapping a item on a list. To save some codeing I tried this:

package info.test.htas;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class xfelt extends ListActivity {

String[] bygning = getResources().getStringArray(R.array.bygning_array);

public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.xfelt); 
    ListView lv = (ListView)findViewById(R.id.xfelt);
    lv.setAdapter(new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, 
            bygning));
}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    if("Byg. 1".equals(bygning[position]))
        {startActivity(byg1.class);}
    else if("Byg. 2".equals(bygning[position]))
        {startActivity(byg2.class);}
    else if("Byg. 3".equals(bygning[position]))
    {startActivity(byg3.class);}
    else if("Byg. 4".equals(bygning[position]))
    {startActivity(byg4.class);}
    else if("Byg. 5".equals(bygning[position]))
    {startActivity(byg5.class);}        
}


}

But the compiler won't recognize the startActivity function. How come?

Peter

2012-04-05 20:09
by unnamet


0

Try startActivity(new Intent(this, byg2.class))

2012-04-05 20:12
by Sam
thx, i just found that solution myselft but thx anyway : - unnamet 2012-04-05 20:38


0

You need to call:

startActivity(new Intent(this, byg1.class)); //and so on with byg2, byg3, byg4...
2012-04-05 20:15
by waqaslam
Ads