From adc407cf38127f356baf1df9664f03a4394a19ee Mon Sep 17 00:00:00 2001 From: annalinewyork Date: Tue, 26 May 2015 21:23:47 -0400 Subject: [PATCH] finially did 1-4 --- src/main/java/nyc/c4q/InitialActivity.java | 93 ++++++++++++++----- src/main/res/layout/activity_initial.xml | 56 ++++++++++- .../nyc/c4q/Unit1AssessmentTestsJava.java | 1 + 3 files changed, 121 insertions(+), 29 deletions(-) diff --git a/src/main/java/nyc/c4q/InitialActivity.java b/src/main/java/nyc/c4q/InitialActivity.java index 2213b83..6ef2204 100644 --- a/src/main/java/nyc/c4q/InitialActivity.java +++ b/src/main/java/nyc/c4q/InitialActivity.java @@ -11,28 +11,73 @@ public class InitialActivity extends Activity { - public int counter = 0; - public SharedPreferences preferences = null; - public final static String TAG = "C4QTAG"; - - public void loadState(){ - Log.d(TAG, "loadState()"); - counter = preferences.getInt("counter", 0); - Log.d(TAG, "loadState(): counter=="+counter); - } - - public void saveState(){ - Log.d(TAG, "saveState()"); - Log.d(TAG, "saveState(): counter=="+counter); - SharedPreferences.Editor editor = preferences.edit(); - editor.putInt("counter", counter); - editor.commit(); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_initial); - preferences = getPreferences(Context.MODE_PRIVATE); - } + public int counter = 0; + public SharedPreferences preferences = null; + public final static String TAG = "C4QTAG"; + + public void loadState() { + Log.d(TAG, "loadState()"); + counter = preferences.getInt("counter", 0); + Log.d(TAG, "loadState(): counter==" + counter); + } + + public void saveState() { + Log.d(TAG, "saveState()"); + Log.d(TAG, "saveState(): counter==" + counter); + SharedPreferences.Editor editor = preferences.edit(); + editor.putInt("counter", counter); + editor.commit(); + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + Log.d(TAG, "onCreate(): counter==" + counter); + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_initial); + preferences = getPreferences(Context.MODE_PRIVATE); + + Button plus = (Button) findViewById(R.id.buttonPlus); + Button minus = (Button) findViewById(R.id.buttonMinus); + final TextView tvCounter = (TextView) findViewById(R.id.tvCounter); + + plus.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + counter++; + Log.d(TAG, "plus:" + counter); + tvCounter.setText(String.valueOf(counter)); + } + } + ); + + minus.setOnClickListener( + new View.OnClickListener() { + @Override + public void onClick(View view) { + counter--; + Log.d(TAG, "minus:" + counter); + tvCounter.setText(String.valueOf(counter)); + } + } + ); + } + + @Override + protected void onPause() { + super.onPause(); + Log.d(TAG, "onPause()"); + } + + @Override + protected void onStop() { + super.onStop(); + Log.d(TAG, "onStop()"); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + Log.d(TAG, "onDestroy()"); + } } diff --git a/src/main/res/layout/activity_initial.xml b/src/main/res/layout/activity_initial.xml index 49e22b0..c6d0a52 100644 --- a/src/main/res/layout/activity_initial.xml +++ b/src/main/res/layout/activity_initial.xml @@ -9,10 +9,56 @@ tools:context="nyc.c4q.InitialActivity" android:id="@+id/activity_initial"> - + android:layout_height="0dp" + android:id="@+id/counterLayout" + android:orientation="horizontal" + android:layout_weight="2"> + + + +