Created
September 16, 2015 01:38
-
-
Save samuelcouch/6fcfad7c8e7d1cc3b912 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.temple.couchlab2; | |
import android.app.Activity; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.FrameLayout; | |
import android.content.Intent; | |
public class backgroundActivity extends Activity { | |
FrameLayout background; | |
Button backButton; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_background); | |
backButton = (Button)findViewById(R.id.back); | |
Intent received = getIntent(); | |
String color = received.getStringExtra("COLOR_FROM_SPINNER"); | |
background = (FrameLayout)findViewById(R.id.background); | |
background.setBackgroundColor(android.graphics.Color.parseColor(color)); | |
backButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
Intent backIntent = new Intent(backgroundActivity.this, MainActivity.class); | |
startActivity(backIntent); | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_background, 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(); | |
//noinspection SimplifiableIfStatement | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.temple.couchlab2; | |
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
import android.widget.AdapterView; | |
import android.widget.ArrayAdapter; | |
import android.widget.Spinner; | |
public class MainActivity extends Activity { | |
Spinner spinnerColor; | |
private ArrayAdapter<String> adapter; | |
private static final String[] colors = { | |
"red", | |
"blue", | |
"green", | |
"black", | |
"white", | |
"gray", | |
"cyan", | |
"magenta", | |
"yellow", | |
"lightgray", | |
"darkgray", | |
"grey", | |
"lightgrey", | |
"darkgrey", | |
"aqua", | |
"fuchsia", | |
"lime", | |
"maroon", | |
"navy", | |
"olive", | |
"purple", | |
"silver", | |
"teal" | |
}; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
spinnerColor = (Spinner)findViewById(R.id.colorspinner); | |
adapter = new ArrayAdapter<String>(this, | |
android.R.layout.simple_spinner_item, colors); | |
adapter.setDropDownViewResource( | |
android.R.layout.simple_spinner_dropdown_item); | |
spinnerColor.setAdapter(adapter); | |
spinnerColor.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { | |
@Override | |
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { | |
Intent colorIntent = new Intent(MainActivity.this, backgroundActivity.class); | |
colorIntent.putExtra("COLOR_FROM_SPINNER", spinnerColor.getSelectedItem().toString()); | |
startActivity(colorIntent); | |
} | |
@Override | |
public void onNothingSelected(AdapterView<?> parent) { | |
spinnerColor.setSelection(5); | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.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(); | |
//noinspection SimplifiableIfStatement | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment