加载数据时显示viewpager选项卡而不加载/进度条

时间:2015-09-01 02:56:45

标签: android android-viewpager broadcastreceiver android-progressbar viewpagerindicator

我正在实施以 View Pager 显示数据,该数据通过 Broad Cast Receiver onReceive() 收到>

但我的确切要求是,我第一次需要读取整个数据,并根据ArrayList size()的大小对数据进行分类后,我需要检查该选项卡是否有任何数据,之后我需要在 NODATA 中显示 ViewPager

我已经通过使用 Async 实现了这一点。但是我的问题是在第一次启动之后直到读取数据,它显示消息为 NODATA

如何避免这种情况?

注意:我的要求是在加载数据时不显示任何加载栏或进度条

code sample

public class InformationTabsActivity extends FragmentActivity implements OnClickListener
{
    protected void onCreate(Bundle savedInstanceState)
    {
        -
        -
        -
    mAsync = new LoadNotificationsASYNC(this);
        mAsync.execute();
        -
        -
        -

    }
    public void getNotificationsList()
    {
        Intent broadcastIntent = new Intent("NOTIFICATION_LISTENER_SERVICEE");
        broadcastIntent.putExtra("command", "list");
        sendBroadcast(broadcastIntent);
    }

        -
        -
        -
    private class LoadNotificationsASYNC extends AsyncTask<Void, Void, Void>
    {
        Context context;

        public LoadNotificationsASYNC(Context mContext)
        {
            context = mContext;
        }

        @Override
        protected void onPreExecute()
        {


        }

        @Override
        protected Void doInBackground(Void... params)
        {

            getNotificationsList();
            return null;
        }

        @Override
        protected void onPostExecute(Void result)
        {
        }
            -
            -
            -

        lass NotificationReceiver extends BroadcastReceiver
    {
        public NotificationReceiver()
        {
        }

        public void onReceive(Context context, Intent intent)
        {
            //Read broadcastIntent and clacify by properties

            if(some cond..)
            {
                mInformationFragment.updateInformationsList();
            }
            else
            {
                mExecutionFragment.updateExecutionsList();
            }


        }

    }

InformationFragment.java

public class InformationFragment extends Fragment implements OnItemClickListener
{
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        if (mInformationsList.size() == 0)
        {
            tv_info.setVisibility(View.VISIBLE);
            tv_info.setText(getResources().getString(R.string.no_infomation_message));
        }
        else
        {
            tv_info.setVisibility(View.GONE);
        }
    }

        -
        -
        -
    public void updateInformationsList()
    {
        if (mInformationsList.size() == 0 && infoTab.firstOnreceiveDone)
        {
            tv_info.setVisibility(View.VISIBLE);
            tv_info.setText(getResources().getString(R.string.no_infomation_message));
            listView.setVisibility(View.GONE);
        }
        else
        {
            listView.setVisibility(View.VISIBLE);
            tv_info.setVisibility(View.GONE);
        }

        mAdapter.notifyDataSetChanged();
    }
}

1 个答案:

答案 0 :(得分:0)

我想你使用AsyncTask。只需实施它onPreExecute()

    @Override
    protected void onPreExecute() {
        //set your message to show nothing til the result come in onPostExecute()
    }