So Im making an app that converts RGB Colors to Hexadecimal (ex. #FFFFFF). I have three edittext for Red, Green and Blu. When I input values for every edittext like (255,255,255) and I click the button the RGB values will be converted to Hexadecimal and will be shown in textview. Can someone help me with the computation here is my codes.
public class MainActivity extends Activity {
public String str ="";
int i,num,numtemp;
EditText showRed, showGreen, showBlue;
String displayStr = "";
Button zero, one, two, three, four, five, six, seven, eight, nine, clear, convert;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
showRed = (EditText)findViewById(R.id.red);
showGreen = (EditText)findViewById(R.id.green);
showBlue = (EditText)findViewById(R.id.blue);
clear = (Button)findViewById(R.id.clear);
convert = (Button)findViewById(R.id.convert);
convert.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
//Convertion Computaion here HELP!!!!!!!!!
}
});
clear.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
str ="";
num = 0;
numtemp = 0;
showRed.setText("");
showRed.requestFocus();
showGreen.setText("");
showBlue.setText("");
displayStr = "";
}
});
}
public void btn1Clicked(View v){
insert(1);
}
public void btn2Clicked(View v){
insert(2);
}
public void btn3Clicked(View v){
insert(3);
}
public void btn4Clicked(View v){
insert(4);
}
public void btn5Clicked(View v){
insert(5);
}
public void btn6Clicked(View v){
insert(6);
}
public void btn7Clicked(View v){
insert(7);
}
public void btn8Clicked(View v){
insert(8);
}
public void btn9Clicked(View v){
insert(9);
}
public void btn0Clicked(View v){
insert(0);
}
private void insert(int j) {
// TODO Auto-generated method stub
if(showRed.hasFocus()){
str = str+Integer.toString(j);
num = Integer.valueOf(str).intValue();
displayStr += Integer.toString(j);
showRed.setText(displayStr);
if((showRed.length() == 3)){
displayStr = "";
showGreen.requestFocus();
}
}
else if(showGreen.hasFocus()){
str = str+Integer.toString(j);
num = Integer.valueOf(str).intValue();
displayStr += Integer.toString(j);
showGreen.setText(displayStr);
if((showGreen.length() == 3)){
displayStr = "";
showBlue.requestFocus();
}
}
else if(showBlue.hasFocus()){
str = str+Integer.toString(j);
num = Integer.valueOf(str).intValue();
displayStr += Integer.toString(j);
showBlue.setText(displayStr);
if((showBlue.length() == 3)){
displayStr = "";
showBlue.clearFocus();
}
}
}
}