-
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
Call activity methods
To run method in parent activity from onPostExecute of AsyncTask, include the activity in the constructor. Solution found in stackoverflow. public class ConverterClass extends Activity … new AsyncNetworkConnection(this); … public void doPostAsyncWork() { public class AsyncNetworkConnection extends AsyncTask ConverterClass converterActivity; … Continue reading
Posted in Android
Leave a comment
nullpointerexception using calendar.settime
I couldn’t work out why this was giving me a null pointer exception. SimpleDateFormat sdf1 = new SimpleDateFormat(“yyyy-MM-dd”); Calendar inputDate; … tempVal = attributes.getValue(“time”); inputDate.setTime(sdf1.parse(tempVal)); To try to identify the problem I tried different ways including: SimpleDateFormat sdf1 = new … Continue reading
Posted in Android
Leave a comment
To check string exists in resource string array
When you have a string array in strings.xml, you can check whether your new string matches an entry in that array: String[] temp_array = getResources().getStringArray(R.array.your_array); if (Arrays.asList(temp_array).contains(myString)) return true;
Posted in Android
Leave a comment
Simple string array to preferences and into ListView
Based on a combination of these stackoverflow links (ArrayList into prefs and arrayList into ListView). Create ArrayList and save to preferences. SharedPreferences prefs = null; ArrayList logs; prefs = PreferenceManager.getDefaultSharedPreferences(this); logs = new ArrayList(); logs.add(“aaaaaaaa”); logs.add(“bbbbbbbb”); logs.add(“cccccccc”); SharedPreferences.Editor editor = … Continue reading
Posted in Android
Leave a comment
SAX parser using AsyncTask to read xml file on net
SAX parser uses less memory than DOM parser, so better for mobiles. Sources were stackoverflow and android developer site but links now lost. This is the laptops.xml file placed on a remote server. <?xml version=”1.0″ encoding=”UTF-8″?> <laptops> <laptop model = … Continue reading
Posted in Android
3 Comments
XML pull parser reading asset
This is my example pulled from a few sources (probably stackoverflow but I no longer have the links). Put employees.xml in assets folder of project. <?xml version=”1.0″ encoding=”UTF-8″?> <employees> <employee> <id>2163</id> <name>Kumar</name> <department>Development</department> <type>Permanent</type> <email>kumar@tot.com</email> </employee> <employee> <id>6752</id> <name>Siva</name> <department>DB</department> … Continue reading
Posted in Android
Leave a comment
Check whether service running
Method found on stackoverflow but it doesn’t appear to be the best answer. After stopping a service, this method may still see it as running. This is presumably because android will clear it our in its own time. The method I … Continue reading
Posted in Android
Leave a comment
Get & set text on view
To get a string/value: EditText e1 = (EditText)findViewById(R.id.count2a); int i = Integer.parseInt(e1.getText().toString()); To set from an activity: ((TextView)findViewById(R.id.score)).setText(Integer.toString(score)); To set from a fragment: ((TextView)view.findViewById(R.id.textView1)).setText(myCurrency1); To use a string from strings.xml: ((Button)findViewById(R.id.button2)).setText(R.string.sched_stop);
Posted in Android
Leave a comment
Download xml file & write to sd card
1. Download xml file The solution that suited me best was largely built on this stackoverflow entry. I put it in an AsyncTask. Remember manifext update: <uses-permission android:name=”android.permission.WRITE_EXTERNAL_STORAGE”></uses-permission> <uses-permission android:name=”android.permission.INTERNET”></uses-permission> <uses-permission android:name=”android.permission.ACCESS_NETWORK_STATE”></uses-permission> In main activity. URL url = null; try … Continue reading
Posted in Android
Leave a comment
Pass data from fragment to activity
This is my preferred solution from the stackoverflow answers seen (mainly this one from Harlo Holmes). Any fragment that should pass data back to its containing activity should declare an interface to handle and pass the data. Then make sure … Continue reading
Posted in Android
Leave a comment