Android Open Source - firstcodeandroid Main Activity






From Project

Back to project page firstcodeandroid.

License

The source code is released under:

MIT License

If you think the Android project firstcodeandroid 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 com.example.activitylifecycletest;
/* ww w .ja va  2s.  c  om*/
//import android.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.Toast;


public class MainActivity extends Activity {
  
  public static final String TAG = "MainActivity";
  
  private Button buttonCopyEditText;
  private EditText editText;
  
  /**
   * this is to test to change pic in ImageView dynamically
   */
  private ImageView imageView;

  /**
   * to test ProgressBar show/hide
   */
  private ProgressBar progressBar;
  
  
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d(TAG, "onCreate");
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        Button startNormalActivity = (Button) this.findViewById(R.id.start_normal_activity);
        Button startDialogActivity = (Button) this.findViewById(R.id.start_dialog_activity);
        startNormalActivity.setOnClickListener(new OnClickListener(){

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

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent intent = new Intent(MainActivity.this, DialogActivity.class);
        startActivity(intent);
      }
          
        });
        
        buttonCopyEditText = (Button) this.findViewById(R.id.copy_edit_text);
        buttonCopyEditText.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.copy_edit_text:
          String inputText = editText.getText().toString();
          Toast.makeText(MainActivity.this, inputText, Toast.LENGTH_SHORT);
          break;
        default:
          break;
        }
      }
          
        });
        
        imageView = (ImageView) this.findViewById(R.id.image_view);
        Button change_image_view = (Button)this.findViewById(R.id.change_image_view);
        change_image_view.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.change_image_view:
          imageView.setImageResource(R.drawable.jelly_bean_to_be_changed);
          break;
        default:
          break;
        }
      }          
        });
        
        // Progress Bar code
        progressBar = (ProgressBar)this.findViewById(R.id.progress_bar);
        Button change_progress_bar = (Button)this.findViewById(R.id.change_progress_bar);
        change_progress_bar.setOnClickListener(new OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        switch(v.getId()){
        case R.id.change_progress_bar:
          if(progressBar.getVisibility() == View.GONE){
            progressBar.setVisibility(View.VISIBLE);
          } else {
            progressBar.setVisibility(View.GONE);
          }
          break;
        case -10:// should be a button here
          // the logic code of progressBarStyleHorizontal
          int progress = progressBar.getProgress();
          progress += 10;
          progressBar.setProgress(progress);
          break;
        default:
          break;
        }
      }
          
        });
    }


    @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;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

com.example.activitylifecycletest.DialogActivity.java
com.example.activitylifecycletest.MainActivity.java
com.example.activitylifecycletest.NormalActivity.java
com.example.activitytest.FirstActivity.java
com.example.listviewtest.FruitAdapter.java
com.example.listviewtest.Fruit.java
com.example.listviewtest.MainActivity.java
com.jikexueyuan.counttime.MainActivity.java
com.jikexueyuan.getmyphonenumber.GetNumber.java
com.jikexueyuan.getmyphonenumber.MainActivity.java
com.jikexueyuan.getmyphonenumber.MyAdapter.java
com.jikexueyuan.getmyphonenumber.PhoneInfo.java
com.vjia.bookcollector.MainActivity.java
com.vjia.coolweather.MainActivity.java
com.vjia.coolweather.activity.ChooseAreaActivity.java
com.vjia.coolweather.activity.WeatherActivity.java
com.vjia.coolweather.db.CoolWeatherDB.java
com.vjia.coolweather.db.CoolWeatherOpenHelper.java
com.vjia.coolweather.model.City.java
com.vjia.coolweather.model.County.java
com.vjia.coolweather.model.Province.java
com.vjia.coolweather.util.HttpCallbackListener.java
com.vjia.coolweather.util.HttpUtil.java
com.vjia.coolweather.util.Utility.java
com.vjia.helloandroid.FirstActivity.java
com.vjia.helloandroid.HelloAndroidActivity.java
com.vjia.hellonote.AddContent.java
com.vjia.hellonote.MainActivity.java
com.vjia.hellonote.MyAdapter.java
com.vjia.hellonote.NotesDB.java
com.vjia.hellonote.SelectAct.java
com.vjia.jokeking.GetJoke.java
com.vjia.jokeking.HttpCallbackListener.java
com.vjia.jokeking.HttpUtil.java
com.vjia.jokeking.Joke.java
com.vjia.jokeking.MainActivity.java
com.vjia.jokeking.MyAdapter.java
com.vjia.locationtest.MainActivity.java