how to add web view in tabbed activity android?

603 views Asked by At

I have seen lot of examples for adding web view in Tabbed activity.but it's not fulfill my need.What I am trying is

Main Activity.java

  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_statement);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
      getSupportActionBar().setDisplayHomeAsUpEnabled(true);
      mSectionsPagerAdapter = new 
      SectionsPagerAdapter(getSupportFragmentManager());
    // Set up the ViewPager with the sections adapter.
      mViewPager = (ViewPager) findViewById(R.id.container);
      mViewPager.setAdapter(mSectionsPagerAdapter);
      TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
      tabLayout.setupWithViewPager(mViewPager);
      name = getIntent().getStringExtra("Username");
  }
     public class SectionsPagerAdapter extends FragmentPagerAdapter {        
       public SectionsPagerAdapter(FragmentManager fm) { super(fm) }
       @Override
       public Fragment getItem(int position) {
        switch(position){
            case 0 :
               TabFragment1 tab1=new TabFragment1(name);
                return tab1;
            case 1:
                TabFragment2 tab2 = new TabFragment2();
                return tab2;
            default:
                return null;
        } }

    @Override
    public int getCount() {
        // Show 3 total pages.
        return 2;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        switch (position) {
            case 0:
                 //new Daily().execute();
                return "Daily";
            case 1:
                //new Week().execute();
                return "Week";  }
        return null;
    } 
 }

 @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        // Respond to the action bar's Up/Home button
        case android.R.id.home:
            this.finish();
            return true;   }
    return super.onOptionsItemSelected(item);
}

TabFragment1.java

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroucontainer,
                         Bundle savedInstanceState) {
          tab1 = inflater.inflate(R.layout.tabfragment1, container, false);
          new Daily.execute();
          return tab1;
      }

        class Daily extends AsyncTask<String,Void,String> {
            String B = "";

            @Override
            protected String doInBackground(String... params) {
            RestAdapter adapter = new RestAdapter.Builder()
                .setEndpoint(Sate_URL) //Setting the Root URL
                .build();
            DAPI api = adapter.create(DAPI.class);
            api.in(
                A,
                B,
                new Callback<Response>() {
                    @Override
                    public void success(Response result, Response response){
                        BufferedReader reader = null;
                        String output = "";
                        try {
                            //Initializing buffered reader
                            reader = new BufferedReader(new 
                            InputStreamReader(result.getBody().in()))    
                            output = reader.readLine();
                           } catch (IOException e) {
                            e.printStackTrace();
                        }
                        web = (WebView)tab1.findViewById(R.id.statement1);
                        web.setWebViewClient(new WebViewClient(){
                            ProgressDialog prDialog;

                            @Override
                            public void onPageStarted(WebView view, String 
                              url, Bitmap favicon) {
                                prDialog = 
                          ProgressDialog.show(getActivity(), null, "loading, please wait...");
                                super.onPageStarted(view, url, favicon);
                            }

                            @Override
                            public void onPageFinished(WebView view, String 
                              url) {
                                prDialog.dismiss();
                                //  
                            mySwipeRefreshLayout.setRefreshing(false);
                                super.onPageFinished(view, url);
                            }
                        });  
                            web.loadUrl(URL);
                   }

                  @Override
                    public void failure(RetrofitError error) {
                        Toast.makeText(getActivity(), error.toString(), 
                    Toast.LENGTH_LONG).show();  }
                });
                return null;
                }
            }

My tabfragment 2 is almost same like tabfragment 1.What i am trying to do is send two parameters to server and show the html content in webview.according to the parameter html table vary for both tab layout.i don't see operation in both layout.Any suggestions or guides will be appreciate.Thanks in advance.

0

There are 0 answers