Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid Activities Question
    text
    copied!<p>Where do i declare a custom button in my main activity class? Can it be on the onStart Method or will it only work in the onCreate Method?</p> <p>Any Help would be appreciated?</p> <p>Also to further illustrate what i am talking about: Here is my activity class.</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(D) Log.e(TAG, "+++ ON CREATE +++"); setContentView(R.layout.main); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter == null) { Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show(); finish(); return; } } @Override public void onStart() { super.onStart(); if(D) Log.e(TAG, "++ ON START ++"); // If BT is not on, request that it be enabled. if (!mBluetoothAdapter.isEnabled()) { Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableIntent, REQUEST_ENABLE_BT); } else { startApp(); } } private void startApp(){ View Patient_Button = findViewById(R.id.patientButton); Patient_Button.setOnClickListener(new OnClickListener() { public void onClick(View v) { //case R.id.patientButton: //Intent b = new Intent(getApplicationContext(), Detailed_ModeActivity.class); //startActivity(b); //break; } } ); View Doctor_Button = findViewById(R.id.doctorButton); Doctor_Button.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent a = new Intent(getApplicationContext(), Detailed_ModeActivity.class); startActivity(a); //break; } } ); View About_Option = findViewById(R.id.aboutButton); About_Option.setOnClickListener(new OnClickListener() { public void onClick(View v) { Intent c = new Intent(getApplicationContext(), About.class); startActivity(c); //break; } } ); </code></pre> <p>*</p> <p>main.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:background="@color/background" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="85dip" android:orientation="horizontal"&gt; &lt;LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:layout_gravity="center" android:orientation="vertical"&gt; &lt;TextView android:text="@string/mainTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="center" android:layout_marginBottom="25dip" android:textSize="24.5sp"/&gt; &lt;!-- Patient Option --&gt; &lt;Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="@string/patientButton" android:id="@+id/patientButton"&gt; &lt;/Button&gt; &lt;!-- Doctor Option --&gt; &lt;Button android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/doctorButton" android:layout_weight="1" android:id="@+id/doctorButton"&gt; &lt;/Button&gt; &lt;!-- Exit Mode --&gt; &lt;Button android:text="@string/exit" android:layout_weight="1" android:id="@+id/exit" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;!-- About Mode --&gt; &lt;Button android:text="@string/aboutButton" android:layout_weight="1" android:id="@+id/aboutButton" android:layout_width="fill_parent" android:layout_height="wrap_content"&gt;&lt;/Button&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload