Skip to content

Instantly share code, notes, and snippets.

View ckashby's full-sized avatar

C K Ashby ckashby

View GitHub Profile
@ckashby
ckashby / Android Navigation Strings
Created August 3, 2014 22:45
Android Navigation Strings
<string name="tasks_button">Tasks</string>
<string name="phone_button">Phone</string>
<string name="music_button">Music</string>
<string name="calendar_button">Calendar</string>
<string name="title_text_music">Welcome to Music</string>
<string name="title_text_calendar">Welcome to Calendar</string>
<string name="title_text_phone">Welcome to Phone</string>
<string name="title_text_tasks">Welcome to Tasks</string>
@ckashby
ckashby / gist:a840981eed03a5af0fa2
Created August 3, 2014 22:43
Android nested LinearLayouts
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MyActivity">
@ckashby
ckashby / gist:78fb434fed7cd78953ab
Created August 3, 2014 22:41
Android Switch / Case ...
@Override // this does not override a super class method. Whats up?
public void onClick(View view) {
switch (view.getId()) {
case R.id.taskButton: {
Intent intent = new Intent(this, TasksActivity.class);
startActivity(intent);
}
break;
EditText etValue = (EditText) findViewById(R.id.etValue);
etValue.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Fires right as the text is being changed (even supplies the range of text)
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
Button btnExample = (Button) findViewById(R.id.btnExample);
btnExample.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Do something here
}
});
public void myClickHandler(View view) {
...
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
// fetch data
} else {
// display error
}
// Get a Spinner and bind it to an ArrayAdapter that
// references a String array.
Spinner s1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter adapter = ArrayAdapter.createFromResource(
this, R.array.colors, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s1.setAdapter(adapter);
// Load a Spinner and bind it to a data query.
private static String[] PROJECTION = new String[] {