-
Recent Posts
Recent Comments
- vidya on Toolbar overlapping listView
- wpadmin on SAX parser using AsyncTask to read xml file on net
- Free Stuff on SAX parser using AsyncTask to read xml file on net
- Crave Freebies on SAX parser using AsyncTask to read xml file on net
- wpadmin on Resources references from the manifest cannot vary by configuration
Archives
- September 2018
- July 2018
- June 2018
- October 2017
- July 2017
- June 2017
- May 2017
- April 2017
- March 2017
- December 2016
- June 2016
- March 2016
- February 2016
- November 2015
- May 2015
- January 2015
- April 2014
- March 2014
- January 2014
- December 2013
- November 2013
- October 2013
- September 2013
- August 2013
- July 2013
- June 2013
- May 2013
Categories
Meta
Author Archives: wpadmin
Set spinner style
This is simple to do in xml. This example makes the spinner look like an edit text. In styles xml file add <style parent=”@android:style/Widget.Spinner” name=”SpinnerAsEditText”><item name=”android:background”>@android:drawable/edit_text</item> </style> In layout file add spinner. <Spinner android:id=”@+id/spinner1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” style=”@style/SpinnerAsEditText” />
Posted in Android
Leave a comment
Create spinner from array
Create a sinner and an adapter, link the two then add to the layout. Use array from strings xml file or created programmatically. LinearLayout myLayout = (LinearLayout) findViewById(R.id.layout1); ArrayList spinnerArray = new ArrayList(); spinnerArray.add(“a”); spinnerArray.add(“b”); spinnerArray.add(“c”); Spinner spinner = new … Continue reading
Posted in Android
Leave a comment
Get API level programmatically
The SDK level (integer) running is available in android.os.Build.VERSION.SDK_INT. int currentapiVersion = android.os.Build.VERSION.SDK_INT; You can then use the int value or the enum corresponding to this int in the android.os.Build.VERSION_CODES class. if (currentapiVersion >= 18) or if (currentapiVersion >= android.os.Build.VERSION_CODES.FROYO)
Posted in Android
Leave a comment
Assign R.id to dynamically created editText
With thanks to stackoverflow, 2 methods, 1 simple and one less simple. 1) You can assign an id after creating the edit text and before adding it to the layout. e.setId(int) This doesn’t put it in the R.java file (so … Continue reading
Posted in Android
Leave a comment
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
Android screenshots
To take a screen shot on an android phone with 4.0 or above. Standard methods: press the power button and the volume down button together for 1-2 seconds or press the power button for 1-2 seconds and select the screen … Continue reading
Posted in Android
Leave a comment
Crash passing args in TextWatcher when orientation has changed
I have a fragment with a TextWatcher on an edittext and the onTextChanged sends the current edittext string to a method in a DatabaseHelper class (extends SQLiteOpenHelper) to check it. If I change the orientation (I do it twice to … Continue reading
Posted in Android
Leave a comment