gpt4 book ai didi

android - picasso , ImageView 没有刷新

转载 作者:行者123 更新时间:2023-11-29 19:30:01 25 4
gpt4 key购买 nike

我正在使用 Picasso 库将图像加载到 ImageView 中,第一次它工作正常但之后如果我返回并进行一些更改再次启动带有图像的 Activity ,它会再次重复相同的图像。 url 始终相同,我已经搜索并应用了许多更改,但它不起作用,请帮忙。

同时,当我关闭应用程序并重新启动它时,它也没有得到刷新,当我在浏览器上点击 url 时,它会显示更新后的图像。

          Picasso.with(this)
.load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
.memoryPolicy(MemoryPolicy.NO_CACHE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(imageView);






public class Activity_result extends AppCompatActivity {
Toolbar toolbar;
private ImageView imageView;
String uiidd;

Button testagain_btn;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);

imageView = (ImageView) findViewById(R.id.imageView_chart);
toolbar = (Toolbar) findViewById(R.id.tool_barresult);
testagain_btn=(Button)findViewById(R.id.btn_testagain);



setSupportActionBar(toolbar);
uiidd = MyApplication.getInstance().getUid();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.color_darkgreen));
}

Picasso.with(this)
.load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
.into(imageView);
/* new Thread(new Runnable() {
@Override
public void run() {
Glide.get(Activity_result.this).clearDiskCache();
}
}).start();

Glide.with(this)
.load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
.skipMemoryCache(true)
.diskCacheStrategy(DiskCacheStrategy.NONE)
//.signature(new StringSignature(System.currentTimeMillis()))
.into(imageView);*/

resultjsonrequest();
testagain_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
/* Intent i = new Intent(Activity_result.this,Activity_knowStatus.class);
startActivity(i);*/

final Dialog dialog = new Dialog(Activity_result.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialoghealthdata);

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));

ImageView dialogButtonCancel = (ImageView) dialog.findViewById(R.id.imageView_close);
Button dialogButtonOk = (Button) dialog.findViewById(R.id.btn_ok);
// Click cancel to dismiss android custom dialog box
dialogButtonCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});

// Your android custom dialog ok action
// Action for custom dialog ok button click
dialogButtonOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(Activity_result.this,Activity_knowStatus.class);
startActivity(i);
}
});

dialog.show();






}
});




}

@Override
protected void onResume() {
super.onResume();
Picasso.with(this)
.load(Config.API_URL+"/sites/default/files/"+uiidd+".png")
.into(imageView);
}

/* @Override
public void onBackPressed()
{

finish();

}*/

private void resultjsonrequest() {

Util.showProDialog(Activity_result.this,"Loading....");

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.GET,
Config.API_URL+"/profile-result-json?userProfileID="+uiidd+"", null, new Response.Listener<JSONObject>() {

@Override
public void onResponse(JSONObject response) {


try {

String txt_totalscore1 = response.getString("patient_score");
txtvw_totalscore.setText(txt_totalscore1);

String txt_chol1 = response.getString("Cholesterol");
txt_chol.setText(txt_chol1);
String cholcolor = response.getString("cholesterolPointColor");
linear_chol.setBackgroundColor(Color.parseColor(cholcolor));

String txt_trigly1 = response.getString("Triglycerides");
txt_trigly.setText(txt_trigly1);
String triglycolor = response.getString("triglycerideScoreColor");
linear_trigly.setBackgroundColor(Color.parseColor(triglycolor));

String txt_hdlchol1 = response.getString("HDLCholesterol %");
txt_hdl_chol.setText(txt_hdlchol1);
String hdlchl1color = response.getString("hDL_cholesterol_scoreColor");
linear_hdl_chol.setBackgroundColor(Color.parseColor(hdlchl1color));

String txt_sysbp1 = response.getString("SystolicBP");
txt_systolicbp.setText(txt_sysbp1);
String systoiccolor = response.getString("systolic_bp_scoreColor");
linear_systolicbp.setBackgroundColor(Color.parseColor(systoiccolor));

String txt_disys1 = response.getString("DiastolicBP");
txt_disystolicbp.setText(txt_disys1);
String disyscolor = response.getString("diastolic_bp_scoreColor");
linear_disystolicbp.setBackgroundColor(Color.parseColor(disyscolor));

String txsugarf1 = response.getString("Blood Sugar Fasting (FF)");
txt_bloodsugarff.setText(txsugarf1);
String sugarfcolor = response.getString("bl_glucode_ff_scoreColor");
linear_bloodsugarff.setBackgroundColor(Color.parseColor(sugarfcolor));


String txsugarp1 = response.getString("Blood Sugar (PP)");
txt_bloodsugarpp.setText(txsugarp1);
String sugarpcolor = response.getString("bl_glucose_pp_scoreColor");
linear_bloodsugarpp.setBackgroundColor(Color.parseColor(sugarpcolor));

String txsmoking1 = response.getString("Smoking");
txt_smoking.setText(txsmoking1);
String smokingcolor = response.getString("Smoking_ScoreColor");
linear_smoking.setBackgroundColor(Color.parseColor(smokingcolor));


String txbmi = response.getString("BMI");
txt_bmi.setText(txbmi);
String bmicolor = response.getString("BMI_ScoreColor");
linear_bmi.setBackgroundColor(Color.parseColor(bmicolor));

String txwalking1 = response.getString("Walking");
txt_walking.setText(txwalking1);
String walkingcolor = response.getString("walkingPointColor");
linear_walking.setBackgroundColor(Color.parseColor(walkingcolor));

String txt_oil1 = response.getString("Oil Intake");
txt_oil.setText(txt_oil1);
String oilcolor = response.getString("oil_ghee_intake_scoreColor");
linear_oil.setBackgroundColor(Color.parseColor(oilcolor));


String txmilk1 = response.getString("MilkDairy Intake");
txt_milk.setText(txmilk1);
String milkcolor = response.getString("milk_dairy_intake_scoreColor");
linear_milk.setBackgroundColor(Color.parseColor(milkcolor));

String txfruit1 = response.getString("Fruits Intake");
txt_fruit.setText(txfruit1);
String fruitcolor = response.getString("Vegitable_ScoreColor");
linear_fruit.setBackgroundColor(Color.parseColor(fruitcolor));

String txt_vegetable1 = response.getString("Vegetables Intake");
txt_vegetable.setText(txt_vegetable1);
String vegetablecolor = response.getString("vegetable_you_intake_scoreColor");
linear_vegetable.setBackgroundColor(Color.parseColor(vegetablecolor));

String txnonveg1 = response.getString("Animal Food");
txt_nonveg.setText(txnonveg1);
String nonvegcolor = response.getString("intake_non_veg_scoreColor");
linear_nonveg.setBackgroundColor(Color.parseColor(nonvegcolor));

String txyoga1 = response.getString("Yoga");
txt_yoga.setText(txyoga1);
String yogacolor = response.getString("yoga_or_stretching_exercis_scoreColor");
linear_yoga.setBackgroundColor(Color.parseColor(yogacolor));

String txmeditation1 = response.getString("MeditationPranayam");
txt_meditation.setText(txmeditation1);
String meditationcolor = response.getString("meditation_prayer_scoreColor");
linear_meditation.setBackgroundColor(Color.parseColor(meditationcolor));

String txstress1 = response.getString("Stress Management");
txt_stress.setText(txstress1);
String stresscolor = response.getString("stress_mgmt_scoreColor");
linear_stress.setBackgroundColor(Color.parseColor(stresscolor));






} catch (JSONException e) {
e.printStackTrace();
Util.showMessageDialog(Activity_result.this, "Server error! Try Again");
}
Util.dimissProDialog();
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
Util.dimissProDialog();
Util.showMessageDialog(Activity_result.this, "Server error! Try Again");
}
});
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
10000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));

// Adding request to request queue
// MyApplication.getInstance().addToRequestQueue(jsonObjReq);
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(jsonObjReq);
}






}

最佳答案

我已经找到了上述问题的解决方案,问题的主要原因是与更新后的图片相同的网址,所以我每次都在带有随机生成数字的网址中添加一个 token ,因此网址被更改并且图片得到更新。

    double token=0;
token=Math.random();
Picasso.with(getApplicationContext()).invalidate("");
Picasso.with(this)
.load(Config.API_URL+"/sites/default/files/"+uiidd+".png?"+token)
.memoryPolicy(MemoryPolicy.NO_CACHE)
.networkPolicy(NetworkPolicy.NO_CACHE)
.into(imageView_chartt);

关于android - picasso , ImageView 没有刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40254833/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com