android-视图持有人稳定性问题

android-视图持有人稳定性问题,第1张

概述我正在将数据上传到服务器,并且如果数据成功上传到服务器,那么我会显示“已保存”,就像您可以看到图像的“已上传”一样.但是问题是,我已经为第一行存储了数据,而在不同的行项目中获取了“已保存”文本holder.textDataStatus.setText(ImageList.get(position).getData());prot

我正在将数据上传到服务器,并且如果数据成功上传到服务器,那么我会显示“已保存”,就像您可以看到图像的“已上传”一样.

但是问题是,我已经为第一行存储了数据,而在不同的行项目中获取了“已保存”文本

holder.textDataStatus.setText(ImageList.get(position).getData());protected voID onPostExecute(String file_url) {  // dismiss the dialog once product deleted  pDialog.dismiss();  try {       // Prepare Save Data       if(strStatusID.equals("0"))       {              Toast.makeText(UploadImagesActivity.this, "Unable to upload", Toast.LENGTH_SHORT).show();                }                else if (strStatusID.equals("1"))                {                    Toast.makeText(UploadImagesActivity.this, "Data Uploaded Successfully", Toast.LENGTH_SHORT).show();                    ImageList.get(position).setData("Saved");                                   Log.d("strData:", filename); // getting correct tapped item                    mAdapter.notifyDataSetChanged();                }                else                {                    Toast.makeText(UploadImagesActivity.this, "Unable to upload", Toast.LENGTH_SHORT).show();                }                } catch (Exception e) {                    // Todo: handle exception                }           if (file_url != null){                Toast.makeText(UploadImagesActivity.this, file_url, Toast.LENGTH_LONG).show();           }

解决方法:

问题是您的适配器不知道该行的数据已上载到服务器.您需要告诉适配器.至于问题“如何告诉适配器?”,您已经有一个列表ImageList.我们只需要编辑它.

现在,向您的MyData类添加另一个布尔值,例如:boolean Uploaded = false;并为其创建getter setter.

将以下行添加到您的getVIEw()中:

if(ImageList.get(position).isuploaded()){    holder.btnUpload.setText("Save");}else{    holder.btnUpload.setText("Upload");}

现在,我们需要在上传完成后将此值设置为true.我们应该只从UploadData类中执行此 *** 作.为此,我们需要将位置发送到UploadData类.我们可以通过如下构造函数来做到这一点:

class UploadData extends AsyncTask<String, String, String> {    private ProgressDialog pDialog;    int position;    //constructor to pass position of row, on which button was clicked to class    public UploadData(int position){        this.position=position;    }     /**    * Before starting background thread Show Progress Dialog    * */    .    .    .    .   protected voID onPostExecute(String file_url) {       // dismiss the dialog once product deleted       pDialog.dismiss();       //after upload is done, set value to true       ImageList.get(position).setUploaded(true);       //Now we need to notify our adapter so that it can reflect changes       mAdapter.notifyDataSetChanged();    .    .

现在,根据您当前的代码,我认为通过构造函数将位置值传递给UploadData确实很困难.因此,您可以通过在类的全局变量中设置一个值来尝试.

编辑1:

将位置传递给您的holder.btnData.SetonClickListener中的全局变量,如下所示:

holder.btnData.setonClickListener(new OnClickListener() {            @SuppressWarnings("deprecation")            @OverrIDe            public voID onClick(VIEw v) {                //pass position into activity's global variable                pos = position/*position from adapter*/;                strPath = ImageList.get(position).getimages().toString();                filename = strPath.substring(strPath.lastIndexOf('/') + 1, strPath.length());                                                      showDialog(DIALOG_DATA);            }        });

如果您需要任何解释,请发表评论.

总结

以上是内存溢出为你收集整理的android-视图持有人稳定性问题全部内容,希望文章能够帮你解决android-视图持有人稳定性问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1088953.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存