I am trying to make a very very simple app as a beginner but it does
not work. The app just has a text bar and a button. Somehow, the call
button does not start a call.
Help please.
package com.tests.helloandroid;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
public class HelloAndroid extends Activity {
EditText mEditText_number = null;
LinearLayout mLinearLayout_no_button = null;
Button mButton_dial = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mLinearLayout_no_button = new LinearLayout(this);
mEditText_number = new EditText(this);
mEditText_number.setText("5551222");
mLinearLayout_no_button.addView(mEditText_number);
mButton_dial = new Button(this);
mButton_dial.setText("Dial!");
mLinearLayout_no_button.addView(mButton_dial);
mButton_dial.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
performDial();
}
});
setContentView(mLinearLayout_no_button);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_CALL) {
performDial();
return true;
}
return false;
}
public void performDial(){
if(mEditText_number!=null){
try {
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
+ mEditText_number.getText())));
} catch (Exception e) {
e.printStackTrace();
}
}//if
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en