Uploaded January 2023 | Updated November 2026, 10 hours ago
Reading and writing JSON with GSON in IntelliJ
My Videos on GSON
- GSON: Deserializing JSON under explicit control of Named fields: youtu.be/HSuVtkdej8Q
- GSON: Use IntelliJ: youtu.be/Qc9EfiepfWs
- GSON: Array or List as root of JSON: youtu.be/trCGXXNVVYE
- GSON: LocalDate Adapter: youtu.be/j2vWhohxBVA
Reading and writing JSON with GSON in IntelliJ
My Videos on GSON
- GSON: Deserializing JSON under explicit control of Named fields: youtu.be/HSuVtkdej8Q
- GSON: Use IntelliJ: youtu.be/Qc9EfiepfWs
- GSON: Array or List as root of JSON: youtu.be/trCGXXNVVYE
- GSON: LocalDate Adapter: youtu.be/j2vWhohxBVA






![Button Tutorial: Android Programming
Demonstration on how to create a button in an Android application. Walks through creating the button and writing the Java code to make it interactive.
Steps and Java code included below in this description.
Steps
1. Create the button on the UI (xml).
2. Get a reference to the button (java)
3. Register a listener (java) [code below]:
myButton.setOnClickListener(...)
Our listener is an anonymous class implementing:
View.OnClickListener
We implement its only function: onClick()
(this is where we put our code).
Aside:
Toast: a message that pops up on the screen.
Java Code:
public class MainActivity extends Activity {
private final String TAG = DemoButtonApp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupMessageButton();
}
private void setupMessageButton() {
// 1. Get a reference to the button.
Button messageButton = (Button) findViewById(R.id.btnDisplayMessage);
// 2. Set the click listener to run my code.
View.OnClickListener myListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i(TAG, You clicked the button!);
Toast.makeText(
MainActivity.this,
You clicked it!,
Toast.LENGTH_LONG
).show();
}
};
messageButton.setOnClickListener(myListener);
}
}
Demo created using the Android Development Tools, build v21.0.0-519525 Button Tutorial: Android Programming](https://i.ytimg.com/vi/Uen8B9p05tI/mqdefault.jpg)


![Post changes to AppServer: Android Programming
Demonstration on posting data to a application server using Android. Server is a sample Google AppEngine web server (http://demoprojectserver1234.appspot.com/). Full code below. Previous tutorial: http://www.youtube.com/watch?v=kJY4SJ3IgGk
package ca.demo.projectserverviewer;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
/**
* Simple activity to demonstrate sending data to the app-server.
*/
public class SimplePostActivity extends Activity {
private static final String TAG = PostActivity;
public static final String SERVER_URL = http://demoprojectserver1234.appspot.com/;
public static final String POST_FILE = post.cgi;
public static final String POST_URL = SERVER_URL + POST_FILE;
private static final String POST_OPTION_APPID = appid;
private static final String POST_OPTION_ITEMID = itemid;
private static final String POST_OPTION_DATA = data;
private static final String MY_APPID = 3fa19507-c746-4dfa-8ded-ec60ef4d30d9;
private static final String MY_ITEMID = 112233;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_simple_post);
}
public void onClick_PostData(View v) {
TextView textView = (TextView) findViewById(R.id.txtDataEntry);
String data = textView.getText().toString();
postDataToServer(MY_APPID, MY_ITEMID, data);
// String uniqueItemId = UUID.randomUUID().toString();
// postDataToServer(MY_APPID, uniqueItemId, data);
}
// Post Changes to Server
// Source: http://www.androidsnippets.com/executing-a-http-post-request-with-httpclient
private void postDataToServer(String appId, String itemId, String data) {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(POST_URL);
try {
// Setup data:
// TODO:- Change the [[ and ]] to the less-than and greater-than (YouTube limit)
List[[NameValuePair]] nameValuePairs = new ArrayList[[NameValuePair]]();
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_APPID, appId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_ITEMID, itemId));
nameValuePairs.add(new BasicNameValuePair(POST_OPTION_DATA, data));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
Log.i(TAG, Post request finished with a status of: + status);
Toast.makeText(this, Post completed w/ status: +status, Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {
Log.e(TAG, Unable to post (protocol): , e);
} catch (IOException e) {
Log.e(TAG, Unable to post (IOException): , e);
}
}
} Post changes to AppServer: Android Programming](https://i.ytimg.com/vi/VunA-CJZ10U/mqdefault.jpg)
