Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to use asynctask in android-support-v4.jar Fragment?
    primarykey
    data
    text
    <p>I have a TabActivity which has two tabs. I load separate Activity in each tab (Activity <strong>A</strong> &amp; <strong>B</strong>). Activity A, which is loaded in tab 1 has <strong>some controls</strong> and a <strong>ListView</strong>. I use <strong>AsyncTask</strong> to load data from a web service for that <strong>ListView</strong>. I had to load another activity when user clicked on ListView item, but that new Activity <strong>C</strong> should be loaded in same selected Tab.</p> <p>I searched on internet and found that i can use <strong>ActivityGroup</strong> ... but at the same time,i found that its deprecated. So using android-support-v4 compatibility <strong>Frangment</strong> were proposed..</p> <p>I downloaded that <strong>android-support-v4.jar</strong> and looked at the <strong>FragmentTabs</strong> sample, I got it how can i use Fragments even in Android 2.1.... so i replaced the two <strong>Activities</strong>, which i was showing in tabs, with two <strong>Fragments</strong></p> <p>But now I dont know how to handle the follow situations:</p> <ol> <li><p>ListView &amp; Other controls does not show when i run the following code.</p></li> <li><p>i have to call AsyncTask ... it will take time to get &amp; parse XML data from the server and Fragment's <strong>onCreateView</strong> is called earlier ... so how can i set the <strong>ListView</strong> in fragment after its <strong>onCreateView</strong> is called?</p></li> <li><p>After ListView item is clicked, i will have to load another fragment <strong>C</strong> within that same <strong>tab</strong> ... how can i achieve this?</p></li> </ol> <p>Code for my Fragment is as follows: </p> <pre><code>public class UpdatesFragment extends Fragment implements IFeedReceiver { ArrayList&lt;Feed&gt; _feeds; Integer _currentPage = 1; ListView _lvUpdates; UserMessage _userMessage; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getFeeds(); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.updates, container, false); this._lvUpdates = (ListView)v.findViewById(R.id.listUpdates); return v; } private void getFeeds() { FeedsCollectorAsyncTask task = new FeedsCollectorAsyncTask( getActivity(), this._currentPage); task.execute(); } //This method is called from AsyncTask upon receiving &amp; parsing data. So i m trying to populate my ListView here @Override public void onFeedReceived(ArrayList&lt;Feed&gt; feeds) { FeedsAdapter adapter = new FeedsAdapter(getActivity(), R.layout.feed_list_item, this._feeds); this._lvUpdates.setAdapter(adapter); // Load detail on item click this._lvUpdates.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int index, long id) { } }); } </code></pre> <p>}</p> <p>Main Tab Activity XML is as follows. </p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;LinearLayout android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dp"&gt; &lt;FrameLayout android:id="@android:id/tabcontent" android:layout_width="0dp" android:layout_height="0dp" android:layout_weight="0"/&gt; &lt;FrameLayout android:id="@+android:id/realtabcontent" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1"/&gt; &lt;TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginBottom="-6dp"/&gt; &lt;/LinearLayout&gt; </code></pre> <p></p> <p>And finally ... </p> <pre><code>public class PlayMakerActivity extends FragmentActivity { /** Called when the activity is first created. */ TabHost tabHost; TabManager mTabManager; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Resources res = getResources(); // Resource object to get Drawables // TabHost tabHost = getTabHost(); // The activity TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost); tabHost.setup(); mTabManager = new TabManager(this, tabHost, R.id.realtabcontent); mTabManager.addTab(tabHost.newTabSpec("Upudates").setIndicator("Updates"), UpdatesFragment.class, null); } } //also included the following AS It IS public static class TabManager implements TabHost.OnTabChangeListener { .... .... .... } </code></pre> <p>You can point me to some example. Your help is greatly appreciated!.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload