Recent site activity

160f. Main.java - click events







  • run the app and watch the LogCat
07-23 23:54:40.785: INFO/saveButton.setOnClickListener(10707): Hi, my contact info is not set yet, someone@ChicagoAndroid.com

























































package com.chicagoandroid.w160;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Main extends Activity
{
static EditText contactInfo;
private Button smsTestButton, saveButton;

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

contactInfo = (EditText) findViewById(R.id.contact_info);
smsTestButton = (Button) findViewById(R.id.sms_test_button);
saveButton = (Button) findViewById(R.id.save_button);
addTestButtonListener();
addSaveButtonListener();
}

private void addTestButtonListener()
{
smsTestButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
smsTestButton.setClickable(false);
String text = (String) contactInfo.getText().toString();
Log.i("smsTestButton.setOnClickListener", text);
Toast.makeText(getApplicationContext(), "Sending: " + text, Toast.LENGTH_SHORT).show();
// SmsSender.sendTest(thisActivity);
}
});
}

private void addSaveButtonListener()
{
saveButton.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
smsTestButton.setClickable(true);
saveButton.setClickable(false);
String text = (String) contactInfo.getText().toString();
Log.i("saveButton.setOnClickListener", (String) contactInfo.getText().toString());
Toast.makeText(getApplicationContext(), "Saving: " + text, Toast.LENGTH_SHORT).show();
// save();
}
});
}
}


Comments