Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Switch between xml pages with button click
Switch between xml pages with button click [message #1323424] Wed, 30 April 2014 08:47 Go to next message
Marisa McMullan is currently offline Marisa McMullanFriend
Messages: 1
Registered: April 2014
Junior Member
Hello this is my first time creating an android application with eclipse so sorry if this question sound stupid.
I have created 3 xml pages and one xml menu page. I have put buttons on the menu pages that I want the user to click and it will take them to a specific xml page.
I have tried a few tutorials but they dont seem to be working. If anyone could take a look at my code please and see where i am going wrong??

Manifest
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >

<activity
android:name="com.example.ifmdb.MainActivity"
android:label="@string/app_name">

<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".checklist"></activity>
<activity android:name=".activity_main"></activity>
<activity android:name=".docket"></activity>
<activity android:name=".duty_of_care"></activity>
</application>
</manifest>


Main activity

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

final Button btnCheck = (Button)findViewById(R.id.btnCheck);
btnCheck.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, checklist.class);
startActivity(intent);
}
});
}

public class checklist extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checklist);

Button btnCheck = (Button) findViewById(R.id.end);

btnCheck.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
finish();
}

});
}
}

activity_main----(menu)

<TextView
android:id="@+id/txtMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_gravity="center"
android:text="@string/please_click_on_the_options_available"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnDOCare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtDOCare"
android:layout_below="@+id/txtDOCare"
android:layout_marginTop="30dp"
android:layout_gravity="center_vertical"
android:onClick="openDOCare"
android:text="@string/duty_of_care" />

<TextView
android:id="@+id/txtDOCare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/btnDock"
android:layout_marginLeft="202dp"
android:layout_marginTop="44dp"
android:layout_gravity="center"
android:text="@string/click_for_duty_of_care"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtVeCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtDOCare"
android:layout_below="@+id/txtMain"
android:layout_marginTop="36dp"
android:text="@string/click_for_vehicle_checklist"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnDOCare"
android:layout_below="@+id/txtVeCheck"
android:layout_marginTop="37dp"
android:onClick="openChecklist"
android:text="@string/checklist" />

<TextView
android:id="@+id/txtDock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/txtDOCare"
android:layout_below="@+id/btnCheck"
android:layout_marginTop="36dp"
android:text="@string/click_for_docket"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnDock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/btnCheck"
android:layout_below="@+id/txtDock"
android:layout_marginTop="38dp"
android:onClick="openDocket"
android:text="@string/docket" />


and so far I have only put code for the button in one xml page, trying to get the first one working before messing with the rest.

checklist

<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/vehicle_safety_checklist"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/txtInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/please_check_each_box"
android:textAppearance="?android:attr/textAppearanceMedium" />

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="0.58" >

<TextView
android:id="@+id/txtInt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="20dp"
android:text="@string/interior"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtEx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/txtInt"
android:layout_alignBottom="@+id/txtInt"
android:layout_alignParentRight="true"
android:layout_marginRight="113dp"
android:text="@string/exterior"
android:textAppearance="?android:attr/textAppearanceMedium" />

<CheckBox
android:id="@+id/cboxFLev"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/txtInt"
android:text="@string/fuel_level" />

<CheckBox
android:id="@+id/cboxTires"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxFLev"
android:layout_alignBottom="@+id/cboxFLev"
android:layout_alignLeft="@+id/txtEx"
android:text="@string/tires_wheels" />

<CheckBox
android:id="@+id/cboxWWash"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxFLev"
android:text="@string/windscreen_washer" />

<CheckBox
android:id="@+id/cboxExhaust"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxWWash"
android:layout_alignBottom="@+id/cboxWWash"
android:layout_alignLeft="@+id/cboxTires"
android:text="@string/exhaust" />

<CheckBox
android:id="@+id/cboxSWheel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxWWash"
android:text="@string/steering_wheel" />

<CheckBox
android:id="@+id/cboxLights"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxSWheel"
android:layout_alignBottom="@+id/cboxSWheel"
android:layout_alignLeft="@+id/cboxExhaust"
android:text="@string/lights_reflectors" />

<CheckBox
android:id="@+id/cboxBrakes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxSWheel"
android:text="@string/brakes" />

<CheckBox
android:id="@+id/cboxELeaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxBrakes"
android:layout_alignBottom="@+id/cboxBrakes"
android:layout_alignLeft="@string/_id_cboxlights"
android:text="@string/exterior_leaks" />

<CheckBox
android:id="@+id/cboxClutch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxBrakes"
android:text="@string/clutch" />

<CheckBox
android:id="@+id/cbocBody"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxClutch"
android:layout_alignBottom="@+id/cboxClutch"
android:layout_alignLeft="@string/_id_cboxeleaks"
android:text="@string/body" />

<CheckBox
android:id="@+id/cboxHorn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxClutch"
android:text="@string/horn" />

<TextView
android:id="@+id/txtEng"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cbocBody"
android:layout_below="@+id/cboxHorn"
android:text="@string/engine"
android:textAppearance="?android:attr/textAppearanceMedium" />

<CheckBox
android:id="@+id/cboxHeater"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="@+id/txtEng"
android:text="@string/heater" />

<CheckBox
android:id="@+id/cboxOil"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/cboxExhaust"
android:layout_below="@+id/cboxHeater"
android:text="@string/oil_level" />

<CheckBox
android:id="@+id/cboxSBelt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxOil"
android:layout_alignBottom="@+id/cboxOil"
android:layout_alignParentLeft="true"
android:text="@string/seat_belts" />

<CheckBox
android:id="@+id/cboxWLight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxCool"
android:layout_alignBottom="@+id/cboxCool"
android:layout_alignParentLeft="true"
android:text="@string/warning_lights" />

<CheckBox
android:id="@+id/cboxBelt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cboxCool"
android:layout_below="@+id/cboxCool"
android:text="@string/belts" />

<CheckBox
android:id="@+id/cboxMirrors"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxWLight"
android:text="@string/mirrors" />

<CheckBox
android:id="@+id/cboxLeaks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cboxBelt"
android:layout_below="@+id/cboxBelt"
android:text="@string/engine_leaks" />

<CheckBox
android:id="@+id/cboxCool"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/cboxOil"
android:layout_below="@+id/cboxOil"
android:text="@string/coolant_level" />

<TextView
android:id="@+id/txtOther"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/cboxLeaks"
android:layout_alignParentLeft="true"
android:text="@string/other"
android:textAppearance="?android:attr/textAppearanceMedium" />

<CheckBox
android:id="@+id/cboxScrew"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtEng"
android:layout_below="@+id/cboxLeaks"
android:text="@string/loose_bolts_screws" />

<CheckBox
android:id="@+id/cboxWTri"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/cboxScrew"
android:layout_alignBottom="@+id/cboxScrew"
android:layout_alignParentLeft="true"
android:text="@string/warning_triangle" />

<CheckBox
android:id="@+id/cboxFire"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/cboxWTri"
android:text="@string/fire_extinguisher_first_aid_kit" />

<TextView
android:id="@+id/txtAddCom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="@string/additional_comments"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtAddComBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/cboxLights"
android:layout_below="@+id/txtAddCom"
android:layout_marginTop="29dp" />

<TextView
android:id="@+id/txtFault"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="27dp"
android:text="@string/in_the_event_of_serious_faults_do_not_drive_the_vehicle"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtDefects"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/txtAddComBox"
android:layout_marginTop="110dp"
android:text="@string/defects"
android:textAppearance="?android:attr/textAppearanceMedium" />

<TextView
android:id="@+id/txtDefectsBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="@+id/cboxScrew"
android:layout_below="@+id/txtDefects"
android:layout_marginTop="25dp" />
Re: Switch between xml pages with button click [message #1324254 is a reply to message #1323424] Wed, 30 April 2014 17:48 Go to previous message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
This is not the right place to ask. See http://www.eclipse.org/forums/index.php/t/225513/
Previous Topic:Eclipse Usage (Java EE and Spring Framework related)
Next Topic:I can't get the web services explorer to work
Goto Forum:
  


Current Time: Fri Apr 26 12:09:44 GMT 2024

Powered by FUDForum. Page generated in 0.08999 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top