Android Programming Tutorials

(Romina) #1
Opening a JAR

NOTE: Eclipse users will also need to add the jtwitter.jar file to their build


path.


The source code to this modified JTwitter implementation can be found on


the CommonsWare Web site.


Step #2: Switch from HttpClient to JTwitter....................................


Now, we can get rid of most of our previous Patchy implementation,


including all of the HttpClient code, and replace it with the delightfully


simply JTwitter API.


Replace the current implementation of Patchy with the following:


package apt.tutorial.two;

import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.View;
import android.util.Log;
import android.widget.Button;
import android.widget.EditText;
import winterwell.jtwitter.Twitter;

public class Patchy extends Activity {
private EditText user=null;
private EditText password=null;
private EditText status=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

user=(EditText)findViewById(R.id.user);
password=(EditText)findViewById(R.id.password);
status=(EditText)findViewById(R.id.status);

Button send=(Button)findViewById(R.id.send);

send.setOnClickListener(onSend);
}

private void updateStatus() {
try {

166
Free download pdf