How to go to a specific activity?
How my application is structured...
Class A extends Activity {
Button cButton = (Button) findViewById(...);
Button dButton = (Button) findViewById(...);
//invoked when cButton is clicked
methodButtonC() {
//Here I want to go to the activity of class C and this is how I have tried to solve it...
Intent intent = new Intent(A.this, C.class);
startActivity(intent);
}
//invoked when dButton is clicked
methodButtonD() {
//Same problem as above but with Class D
}
}
// Base Class for C & D, No real purpose except sharing som methods to C & 开发者_开发问答D (should probobly be abstract?)
Class B extends A {
// vairables and methods for inheritance
}
Class C extends B {
// uses derived methods and variables from Class B
}
Class D extends B {
// uses derived methods and variables from Class B
}
When I run the application and click the Button C or D error occurs. How shall I do it?
I would think you have to override the onCreate and load your view from xml by calling setContentView(...) before you try finding your buttons with findViewById(...)
@Override public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.<yourview>);
buttonX = findViewById (...);
}
精彩评论