Monthly Archives: September 2013

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