I am working on a a search component to a twitter app. I have been doing the parsing in a regular class and tried to add views to the activity that way, but it didn’t work. In my post:
Android 2.3.3: Crash when getting a LinearLayout from (LinearLayout)findViewById(R.id.<linear_layout_id>)
a very helpful stackoverflow user told me that my best choice would be putting all the parsing calls into an asynctask and adding the views to the activity on the onPostExecute().
So my question is, can I select a layout from the XML, add a view to it, and save it inside an asyctask’s onPostExecute()?
yes off course, either pass the view or pass the Activity containing the view to the constructor of the AsyncTask. Just make sure you don’t use those objects in the doInBackground method.
In fact I have done something similar just last week:
listView is a ListView passed as constructor argument same as context, which is the Context (activity) containing the view.
EDIT: Say you define AsyncTask then:
For more info you can read Android docs: http://developer.android.com/reference/android/os/AsyncTask.html