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
Try startActivity(new Intent(this, byg2.class))
You need to call:
startActivity(new Intent(this, byg1.class)); //and so on with byg2, byg3, byg4...