I am trying to create clickable textviews in Android. I'm a complete noob when it comes to java and the Android platform, so please take it easy on me.
Here's what I have right now:
public class Hypertension extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void clickHandler(View v){
if (v.getId() == R.id.tvRed) {
startActivity(new Intent(getApplicationContext(), Red.class));
}
if (v.getId() == R.id.tvGreen) {
startActivity(new Intent(getApplicationContext(), Green.class));
}
}
}
And I've added the line: android:onClick="clickHandler"
to the appropriate textviews in the main.xml
When I run the program on the emulator, I get the main layout to display, but when I click on the text views, it appears that nothing happens. I'm trying to get it to run an activity when I click on it.
EDIT: In an attempt to debug myself, I changed the textviews to buttons in order to simplify things. I click the button, and the app crashes, and I must force quit. I don't know if that helps at all, just thought I should mention.