Android Open Source - CSCI567---Workspace Main Activity






From Project

Back to project page CSCI567---Workspace.

License

The source code is released under:

MIT License

If you think the Android project CSCI567---Workspace listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package csci567.checkboxexample;
// w  ww .  ja v a 2 s  . co m
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;


public class MainActivity extends Activity implements OnClickListener {

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    CheckBox checkBox1 = (CheckBox) findViewById(R.id.checkBox1);
    CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);
    checkBox1.setOnClickListener(this);
    checkBox2.setOnClickListener(this);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
  }
  
  public void onCheckboxClicked(View view) {
      // Is the view now checked?
      boolean checked = ((CheckBox) view).isChecked();
      // Check which checkbox was clicked
      switch(view.getId()) {
        case R.id.checkBox1:
              if (checked){
                TextView txt = (TextView) findViewById(R.id.textView1);
                //Replace the text in the textView with the following text.      
                txt.setText("Check Box 1 Checked");
                Toast.makeText(this, "Check Box 1 Checked", Toast.LENGTH_LONG).show();
              }                
              else{
                TextView txt = (TextView) findViewById(R.id.textView1);
                //Replace the text in the textView with the following text.      
                txt.setText("Check Box 1 Unchecked");
                Toast.makeText(this, "Check Box 1 Unchecked", Toast.LENGTH_LONG).show();
              }
              break;
        case R.id.checkBox2:
              if (checked){
                TextView txt = (TextView) findViewById(R.id.textView1);
                //Replace the text in the textView with the following text.      
                txt.setText("Check Box 2 Checked");
                Toast.makeText(this, "Check Box 2 Checked", Toast.LENGTH_LONG).show();
              }                
              else{
                TextView txt = (TextView) findViewById(R.id.textView1);
                //Replace the text in the textView with the following text.      
                txt.setText("Check Box 2 Unchecked");
                Toast.makeText(this, "Check Box 2 Unchecked", Toast.LENGTH_LONG).show();
              }
              break;
            
      }
  }


  @Override
  public void onClick(View view) {
    switch(view.getId()) {
        case R.id.checkBox1:
          //Fall through into checkBox2
        case R.id.checkBox2:
          onCheckboxClicked(view);
          break;
    }
    
  }

}




Java Source Code List

com.example.linearlayoutexample.MainActivity.java
com.example.relativelayoutexample.MainActivity.java
csci567.FragmentExample.Fragmentmanageractivity.java
csci567.FragmentExample.MainActivity.java
csci567.FragmentExample.MyFragment.java
csci567.FragmentExample.MyStaticFragment.java
csci567.alarmexample.MainActivity.java
csci567.alarmexample.SampleAlarmReceiver.java
csci567.asynctaskexample.MainActivity.java
csci567.buttonexample.MainActivity.java
csci567.checkboxexample.MainActivity.java
csci567.doodleexample.MainActivity.java
csci567.doodleexample.SampleAlarmReceiver.java
csci567.doodleexample.SampleBootReceiver.java
csci567.doodleexample.SampleSchedulingService.java
csci567.eventreceiver.DataReceiver.java
csci567.eventreceiver.MainActivity.java
csci567.eventreceiver.RebootReceiver.java
csci567.helloworld.MainActivity.java
csci567.simpledbexample.DBHelper.java
csci567.simpledbexample.MainActivity.java
csci567.suggestionapp.MainActivity.java
csci567.writefile.MainActivity.java
org.ndeftools.boilerplate.AndroidNfcActivity.java
org.ndeftools.boilerplate.DefaultNfcBeamWriterActivity.java
org.ndeftools.boilerplate.DefaultNfcReaderActivity.java
org.ndeftools.boilerplate.DefaultNfcTagWriterActivity.java
org.ndeftools.boilerplate.NdefRecordAdapter.java
org.ndeftools.nfcdemo.TagViewer.java
org.ndeftools.nfcdemo.simulator.FakeTagsActivity.java
org.ndeftools.nfcdemo.simulator.MockNdefMessages.java