0

I am trying to make a tab bar application in android, after searching in google i found some tutorial and i succeeded. I want 3 tabs, when i click on 1st tab some data will be taken from server using asyntask and show the progressdialog in frontend, but the progressdialog is capturing the whole screen(with tabbar) and because of that i can't be able to switch the 2nd or 3rd tab.

Expected Output: Whenever i click on any tab a data will be taken from server in background, as i know data is loaded in background so for that time i want to switch 2nd tab or any other tab. 


package com.tabexample;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;

import android.view.View;
import android.view.View.OnClickListener;

import android.view.WindowManager;
import android.widget.Button;

public class ArrowsActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.arrowspage);

        Button back = (Button) findViewById(R.id.BackButton2);



       back.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            ProgressDialog p = new ProgressDialog(getParent());
            p.setMessage("Loading");
            p.setCancelable(false);
            p.show();
            p.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);

        }
    });


    }
}



package com.tabexample;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;


public class EditActivity extends ListActivity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, mListContent));   
        ListView lv = getListView();
        lv.setOnItemClickListener(new OnItemClickListener() 
        {
             public void onItemClick(AdapterView<?> parent, View view, int position, long id)
             {
                 startActivity(new Intent(EditActivity.this, OptionsActivity.class));
             }
        }); 


    }


    private static String[] mListContent={"Item 1", "Item 2", "Item 3"};
}



package com.tabexample;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;

public class OptionsActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.optionspage);

        Button back = (Button) findViewById(R.id.BackButton1);
        Button next = (Button) findViewById(R.id.NextButton1);


    }
}

package com.tabexample;


import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TabHost;



public class TabExmapleActivity extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tablayout);
        TabHost tabHost = getTabHost();       

        tabHost.addTab(tabHost.newTabSpec("tab1")
              .setIndicator("OPT")
              .setContent(new Intent(this, ArrowsActivity.class)));

        tabHost.addTab(tabHost.newTabSpec("tab2")
              .setIndicator("EDIT")
              .setContent(new Intent(this, EditActivity.class)));

        tabHost.setCurrentTab(0);
    }
}




<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout02" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/TextView02" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Arrows Page">
    </TextView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/BackButton2"
        android:text="Back" android:layout_below="@+id/TextView02">
    </Button>

<Button android:id="@+id/Button01" android:layout_below="@id/BackButton2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Indeterminate Dialog"></Button>
<Button android:id="@+id/Button02" android:layout_below="@id/Button01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Select"></Button>
</RelativeLayout>






<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout01" android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <TextView android:id="@+id/TextView01" android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Options Page">
    </TextView>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/BackButton1"
        android:text="Back" android:layout_below="@+id/TextView01">
    </Button>
    <Button android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/NextButton1"
        android:text="Next" android:layout_toRightOf="@+id/BackButton1"
        android:layout_below="@+id/TextView01"></Button>
</RelativeLayout>





<?xml version="1.0" encoding="utf-8"?>
<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">

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" >
        </FrameLayout>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true">
        </TabWidget>
    </RelativeLayout>

</TabHost>



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.tabexample"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".TabExmapleActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="ArrowsActivity"></activity>
        <activity android:name="EditActivity"></activity>
        <activity android:name="OptionsActivity"></activity>
    </application>

</manifest>

Pradeep
  • 1,043
  • 7
  • 12

2 Answers2

0

Just Put Progressbar for the child Activitys you are adding in TabHost .

First it will show progress bar of first activity in onCreate which you set as current activity and if you click on next tab it will show its progress dialog

K_Anas
  • 31,226
  • 9
  • 68
  • 81
  • In 1st tab i have created an activity and in that activity a progressdialog code is written as follows :- ProgressDialog dialog = new ProgressDialog(getParent()); dialog.setMessage("LOADING..."); dialog.setCancelable(false); dialog.show(); but i cant be able to switch the tab. – Pradeep Jul 03 '12 at 08:47
0

if i get you correctly, you need to access the below activity components when the progress dialog is active.

for this you need to make non-modal/modeless progress dialog. non-modal dialogs will allow you to accept events by behind ui components

please refer the post below

timed modeless dialog

Community
  • 1
  • 1
sunil
  • 6,444
  • 1
  • 32
  • 44
  • i tried to add a flag --> dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); but the progressdialog is showing in next tab also – Pradeep Jul 03 '12 at 08:39
  • please post your code. i think you are calling the same `Asynctask` in other two tabs also. this must be your logical issue. but with the above code, you can access the UI components below the `ProgressDialog`. am i right ? – sunil Jul 03 '12 at 08:44
  • by the way i just want the progressdialog in 1st tab and by that time i want to be able to access the 2nd tab, if you want the code i m editing my question – Pradeep Jul 03 '12 at 08:57