Android Studio:从网址

时间:2016-03-31 00:18:05

标签: java android

大家好,我有一些问题......

我正在制作带有图像视图的新应用程序并从网上加载图像,我编写代码并第一次下载图像但下次当我打开应用程序时它会加载第一次相同的图像并在我的服务器上我替换了这个与其他图像(具有相同的名称和扩展名)的图像。我需要你的帮助

这是我的片段代码:

package layout;



 import android.os.Bundle;
   import android.os.CountDownTimer;
   import android.support.v4.app.Fragment;
   import android.support.v4.view.ViewPager;
   import android.view.LayoutInflater;
   import android.view.View;
   import android.view.ViewGroup;
   import android.webkit.WebSettings;
   import android.webkit.WebView;
   import android.webkit.WebViewClient;
   import android.widget.FrameLayout;
   import android.widget.LinearLayout;
   import android.widget.ProgressBar;

   import com.example.pecurka.clubdraganm.R;
   import com.loopj.android.image.SmartImageView;


   public class second_frag extends Fragment {
private ProgressBar progress;
private String url;



@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.second_frag, container, false);
    url = getArguments().getString("msg");

    SmartImageView myImage2 = (SmartImageView) v.findViewById(R.id.my_image2);
    myImage2.setImageResource(R.drawable.logo);
    myImage2.setImageUrl(url);



    FrameLayout r_frag2 = (FrameLayout) v.findViewById(R.id.reservieren_frag2);
    r_frag2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ViewPager pager = (ViewPager) getActivity().findViewById(R.id.viewPager);
            pager.setVisibility(View.GONE);

            LinearLayout indicator = (LinearLayout) getActivity().findViewById(R.id.indicator);
            indicator.setVisibility(View.GONE);

            progress = (ProgressBar) getActivity().findViewById(R.id.progressBar1);
            progress.setVisibility(View.VISIBLE);

            WebView web = (WebView) getActivity().findViewById(R.id.webView);
            web.loadUrl("http://plastifikacija-bogdanic.com/dm/reservierung");
            web.setWebViewClient(new MyWebViewClient());

            WebSettings webSettings = web.getSettings();
            webSettings.setJavaScriptEnabled(true);
            getActivity().setTitle("Reservierung");


        }
    });



    return v;





}

public static second_frag newInstance(String text) {

    second_frag f = new second_frag();
    Bundle b = new Bundle();
    b.putString("msg", text);

    f.setArguments(b);

    return f;
}


private class MyWebViewClient extends WebViewClient {


    @Override
    public void onPageFinished(WebView view, String url) {
        progress.setProgress(100);
        progress.setVisibility(View.GONE);
        WebView web = (WebView) getActivity().findViewById(R.id.webView);
        web.setVisibility(View.VISIBLE);

        FrameLayout reservieren = (FrameLayout) getActivity().findViewById(R.id.submitbtn);
        reservieren.setVisibility(View.VISIBLE);

        super.onPageFinished(view, url);

    }


}

}

我有三个与此相同的片段,这些片段在viewpager中显示,我将替换服务器上的图像,图片在我的应用中下次启动时自动加载。

由于

1 个答案:

答案 0 :(得分:0)

您正在使用SmartImageView库,该库将磁盘上的映像缓存以供将来加载。如上所述:http://loopj.com/android-smart-image-view/

如果您已更新服务器上的图像并想要清除缓存,则可以使用以下命令执行此操作:

WebImageCache cache = new WebImageCache(context);
cache.clear();

或者您可以在此路径上手动删除磁盘中的缓存文件:“/ web_image_cache /”