Create Instance Of New Class In Android
Solution 1:
Start the activity like this.
budgetPeriodButton.setOnClickListener(new View.OnClickListener() {
publicvoidonClick(View v) {
Intent intent = new Intent(v.getContext(), BudgetPeriod.class);
startActivity(intent);
}
});
and make sure you declared the activity in AndroidManifest.xml
<activityname=".BudgetPeriod"android:name="Budget" />
Solution 2:
First of All, you can not create an instance of Activity like this, and calling method of it. Like simple Java Class. Because Android Activity has its own life cycles of calling methods.
You have to start Activity BudgetPeriod Using Intent in Button's onClick()
.
Change your method like,
budgetPeriodButton.setOnClickListener(new View.OnClickListener() {
publicvoidonClick(View v) {
Intent intent = new Intent(v.getContext(), BudgetPeriod.class);
startActivity(intent)
}
And register following BudgetPeriod Activity in AndroidManifest.xml file.
Solution 3:
Activity in android dosen't start by creating instance like this:
you need to use Intents to start activity like below
budgetPeriodButton.setOnClickListener(newView.OnClickListener() {
@OverridepublicvoidonClick(View v) {
Intentintent=newIntent(v.getContext(), BudgetPeriod.class);
startActivity(intent);
}
and you need to register that activity in manifest.xml file like:
<activityandroid:name=".BudgetPeriod"
/>
you can make yourself clear about intents by Following links: http://www.vogella.com/articles/AndroidIntent/article.htmlhttp://developer.android.com/reference/android/content/Intent.html
Post a Comment for "Create Instance Of New Class In Android"