Sorry that I am very new to the android development and now that I would like to workout that when the user presses a button, it will initiate Actitity2, and similarly when the user press the cancel button in Activity2, it will back to the original activity.
I have referenced to the book about writing app but it seems cannot work, the coding is looks simple and as follows:
public class NameIndex extends Activity
{
// called when the activity is first created
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.name_index);
public button_cancel_click (View view) { /////// <-- ERROR AT THIS LINE
Intent intent = new Intent (this, GameIndex.class);
startActivity(intent);
}
} // end method onCreate
}
The xml layout as follows:
<TableRow android:id="@+id/tableRow1"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:layout_span="2" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="1"
android:layout_weight="1"
android:onClick="button_cancel_click"
android:text="Cancel" />
</TableRow>
The Eclipse reports the above error line as “button_cancel_click cannot be resolved to a type“, and that for
view “Illegal modifier for parameter view; only final is permitted“.
How could this be solved?
you are writing the definition of button_cancel_click function in OnCreate function body correct it like this: