Monthly Archives: November 2013

Textwatcher example

A simple example to watch or text changed. ((EditText)view.findViewById(R.id.manualCodeEntry)).addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable arg0) { // TODO Auto-generated method stub } @Override public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub … Continue reading

Posted in Android | Leave a comment

Simple listview example

1. Start with a simple layout for each line. <?xml version=”1.0″ encoding=”utf-8″?> <TextView xmlns:android=”http://schemas.android.com/apk/res/android” android:layout_width=”fill_parent” android:layout_height=”fill_parent” android:padding=”10dp” android:textSize=”20sp” > </TextView> Create activity extending ListActivity. public class WordListActivity extends ListActivity { static final String[] words = new String[] { “Apple”, “Bread”, … Continue reading

Posted in Android | Leave a comment

Eclipse oddities

1. Unbound prefix I was getting an error in a layout file: error parsing xml, unbound prefix. It turned out that a line of xml pasted in from another (working) layout file contained the prefix ‘android1:’, whereas all other lines … Continue reading

Posted in Android | Leave a comment

Examples of setting colours dynamically

Buttons and textviews. button.setBackgroundColor(Color.parseColor(“#bdbdbd”)); yourTextView.setTextColor(0xffbdbdbd); textView.setTextColor(getResources().getColor(R.color.sf_yellow)); Where colors.xml (in values folder) contains <resources> <color name=”sf_yellow”>#f5e214</color> </resources> On canvas simply: canvas.drawColor(Color.BLUE); or for greater control: float[] color=new float[3]; // HSV (0..360,0..1,0..1) //color[0]=(float)(Math.random()*360); color[0]=197; color[1]=1; color[2]=1; canvas.drawColor(Color.HSVToColor(color));  

Posted in Android | Leave a comment