Thanks ians for your response. I really appreciate it. "this" was what I needed to not get an error. I've posted the code to simplify this and was hoping you could let me know what I'm missing. I've included the code for both classes below. In the onItemSelected method I change arg2 to j which represents the selected item in the list view. I know this works because if you select the 4th item in the list it starts the startNewScreen method at the bottom of the first class. I put the intent code in as you wrote. I added the 'j' variable in the putExtra method of the intent and am trying to get the other class to reconize it so I can use it in an if statement in the second class.
public class MainScreen extends Activity {
public String [] array1={"G1", "iPhone", "Android", "apple", "Google"};
ListView listview1;
TextView txtview1;
int i;
public static int j;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
txtview1=(TextView)findViewById(R.id.textview1);
listview1=(ListView)findViewById(R.id.listview1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array1);
adapter.setDropDownViewResource(android.R.layout.s imple_list_item_1);
listview1.setAdapter(adapter);
listview1.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
j = arg2;
if (j > 3) {
startNewScreen();
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public void startNewScreen () {
Intent variablepass = new Intent("myintent");
variablepass.putExtra("mydata", j);
Intent intent = new Intent(MainScreen.this, MainScreen2.class);
startActivity(intent);
}
}
__________________________________________________ _____________________________________________
Public class MainScreen2 extends Activity {
TextView textview2;
public static int k;
public int j;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main2);
textview2=(TextView)findViewById(R.id.textview2);
textview2.setText("Hello2");
IntentFilter f = new IntentFilter("myintent");
f.addAction("myintent");
BroadcastReceiver r = new BroadcastReceiver() {
public void onReceive(Context c, Intent variablepass) {
if (j>3) {
textview2.setText("Google");
};
}
};
this.registerReceiver(r,f);
}
}