Hello I would like my application to allow a user to input a number 1 to 16, press a button and then have the input number's hex equivalent shown on screen as a toast message and also store is hex in a single byte. Now i've most of it down and ready to go, its just i'm having problems with the input string to hex conversion. Would anyone be able to give me some help with the conversion?? I'm sure there must be an easy way of doing this??
For example if i input 1 it would display 0x31 on screen in a toast and 0x31 would be stored in a byte.
thanks
code:
public class MainActivity extends Activity {
private static String toastMsg;
private static String input;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button genButton = (Button) findViewById(R.id.btnGen);
final EditText inputText = (EditText) findViewById(R.id.etxtInput);
final TextView outputText = (TextView) findViewById(R.id.txtOutput);
genButton.setOnClickListener(new OnClickListener() {
public void onClick(View view){
input = inputText.getText().toString();
toastMsg = input;
toast();
}
});
}
//-----TOAST---------------------------------//
public void toast() {
Toast toast= Toast.makeText(getBaseContext(), toastMsg, Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, -100);
toast.show();
}
}