package app.Test;
import com.test.android.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnKeyListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
public class appTest extends Activity {
private EditText edittext;
protected double value;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
addKeyListener();
}
private void addKeyListener() {
edittext = (EditText) findViewById(R.id.editText1);
edittext.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN)
&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
if(!edittext.getText().toString().equals(""))
value = Double.parseDouble(edittext.getText().toString());
else
value = 0;
Toast.makeText(this, "Value:" + value, Toast.LENGTH_SHORT).show();
return true;
}
if(!OnKeyTurn)
value = 0;
return false;
}
});
}
}
No comments:
Post a Comment