Using Button To Open New View
Solution 1:
You probably are wanting to use multiple activities.
Please refer to Activities and then Starting An Activity in particular.
To make a long story short, you can think about an activity as similar to a web page. Most of the time when a user clicks on a button in a web browser, that triggers a query (Intent
in Android) which brings the user to a new page (Activity
in Android). Your initial screen with the two buttons would then be one activity, and the pipes and tubes sections would be two separate additional activities.
Solution 2:
You can do it as follows. Make an xml with two buttons i.e piping and tubing in the java file for the xml, set listener for the buttons. In the listeners, try starting a new activity.
xml file can be like this,
<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#9999FF"
><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:gravity="center_horizontal"android:text="Main Menu"android:textStyle="bold"android:textSize="15px"android:paddingTop="10px"android:paddingBottom="10px"android:textColor="#FFFFFF"android:background="#9966FF"
/><Buttonandroid:layout_width="wrap_content"android:text="Purchase Requisition"android:layout_marginLeft="60px"android:layout_height="35px"android:id="@+id/purchaseRequisitonButton"android:layout_marginTop="40px"
/><Buttonandroid:layout_width="wrap_content"android:text="Purchase Order"android:layout_marginLeft="65px"android:layout_height="35px"android:id="@+id/purchaseOrderButton"android:layout_marginTop="10px"
/></LinearLayout>
Java file for this can be like...
package guide.training.iApproval;
import android.accounts.OnAccountsUpdateListener;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
publicclassMainMenuextendsActivity {
/** Called when the activity is first created. */@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);
ButtonpurchaseRequisitionButton= (Button) findViewById(R.id.purchaseRequisitonButton);
ButtonpurchaseOrderButton= (Button) findViewById(R.id.purchaseOrderButton);
//Listener for the Purchase Requisition button
purchaseRequisitionButton.setOnClickListener
(newButton.OnClickListener()
{
publicvoidonClick(View v)
{
Intentintent=newIntent(MainMenu.this,guide.training.iApproval.myJava.class);
startActivity(intent);
}
}
);
//Listener for the Purchase Order button
purchaseOrderButton.setOnClickListener
(newButton.OnClickListener()
{
publicvoidonClick(View v)
{
}
}
);
}
}
Solution 3:
This method worked for me
View.OnClickListener handler = new View.OnClickListener(){
publicvoidonClick(View v) {
switch (v.getId()) {
case R.id.button1:
setContentView(R.layout.layout1);
break;
case R.id.button2:
setContentView(R.layout.layout2);
break;
case R.id.button3:
setContentView(R.layout.layout3);
break;
case R.id.button4:
setContentView(R.layout.layout4);
break;
}
}
};
findViewById(R.id.button1).setOnClickListener(handler);
findViewById(R.id.button2).setOnClickListener(handler);
findViewById(R.id.button3).setOnClickListener(handler);
findViewById(R.id.button4).setOnClickListener(handler);
}
Solution 4:
If you want to keep the applications separate, use the following to fire the required app:
Intentintent=newIntent(Intent.ACTION_MAIN);
intent.setComponent(newComponentName("com.pkg.address","com.pkg.address.MainActivity"));
startActivity(intent);
In each of your 'pipes' and 'tubing' app, register for the ACTION_MAIN
intent so that it is launched. Read up on Intents and Intent Filters.
Post a Comment for "Using Button To Open New View"