I am trying to write my first app- a simple application where the user enters a hex color code (EditText), hits enter (Button), and the background color of a ImageView is changed to the user's entered hex code. How I see it, I will have to gettext from the edittext, write the gettext to a file, then edit the file to append 0xAA before the hex code so that it can be entered in ImageView.setBackgroundColor(0xAA"HEXHEX"). Please let me know how I can do this, or if that is even the correct way to do this.
Here is my java so far (on button click, bg color changes to white, clear reverts it to black)
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.Button;
import android.widget.ImageView;
import android.view.View;
public class ChkhexActivity extends Activity {
private EditText hex;
private Button chk;
private Button clear;
private ImageView view;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initControls();
}
private void initControls()
{
hex = (EditText)findViewById(R.id.hex);
chk = (Button)findViewById(R.id.chk);
clear = (Button)findViewById(R.id.clear);
view = (ImageView)findViewById(R.id.view);
chk.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ Chk(); }});
clear.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ Clear(); }});
}
private void Chk()
{
view.setBackgroundColor(0xFFffffff);
}
private void Clear()
{
hex.setText("");
view.setBackgroundColor(0xFF000000);
}
}