当我在视图中更改选项卡“ontabchange()”时运行onresume()方法

时间:2011-07-04 09:14:56

标签: android

我把代码放在onResume()方法中,每当我再次通过选项卡点击加载它时,但问题是,当我第一次点击选项卡时,数据首次从服务器加载到列表视图当我更改选项卡并再次加载它强制关闭并给出“数组索引超出绑定的异常”。我认为这是因为它不会删除以前加载的数据,因此如何删除或重新加载选项卡上的新数据,以便不发生异常?这意味着在通过onResume()加载新数据之前如何删除旧数据?

protected void onPause(){          super.onPause();

 }


 protected void onResume()
{

   super.onResume();

   **new ProgressTask6().execute();**

}

private class ProgressTask6 extends AsyncTask<String, Void, Boolean> {
 private ProgressDialog dialog;
            private Context context;
            @Override
            protected void onPreExecute() {
                 dialog = new ProgressDialog(OpeningToday.this);
                 dialog.setMessage("Processing...");
                 dialog.setIndeterminate(true);
                 dialog.setCancelable(false);
                 dialog.show();
        }

            @Override
        protected void onPostExecute(final Boolean success) {

                if (dialog.isShowing())
                {
                dialog.dismiss();
                setListAdapter(new MyAdapter(OpeningToday.this));
            }


     }
        @Override
        protected Boolean doInBackground(String... args) {
              try{ 


         } catch (Exception e){
           Log.e("tag", "error", e);
           return false;
        }
        return null;
       }
        class MyAdapter extends BaseAdapter implements OnClickListener
        {


                    }        

                    @Override
                    public int getCount() {
                       }                        }

                    /* Not implemented but not really needed */
                    @Override
                    public Object getItem(int position) {
                        return null;
                    }

                    /* Not implemented but not really needed */
                    @Override
                    public long getItemId(int position) { 
                        return 0;
                    }

                    @Override
                    public View getView(int position, View ConvertView, ViewGroup parent) 
                    {
                        View v = inflater.inflate(R.layout.listitem_layout, parent, false);
                       // Log.i("array galoijewdh..",keywordresulttab.array_galleryname[position]);
                        Log.i("saurabh trivedi","saurabh trivedui");
                       // Variables.a=3;
                        String   gallerynames = keywordresulttab.array_galleryname[position];
                        String  addresses = keywordresulttab.array_address[position];            
                        TextView tv = (TextView) v.findViewById(R.id.barrio);
                        tv.setText(gallerynames);
                        tv = (TextView) v.findViewById(R.id.ciudad);
                        tv.setText(addresses);
                        ((BaseAdapter)(getListAdapter())).notifyDataSetChanged();
                        return v;
                    }
                @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }

                    }

}

1 个答案:

答案 0 :(得分:0)

初始化onPause()中与onResume()相反的索引/删除数据。

根据经验(根据activity lifecycle) - 用相反的方法清洁你需要的东西 -

  • onCreate() - onDestroy()
  • onStart() / onRestart() - onStop()
  • onResume() - onPause()