如何在Android中定期刷新数据?

如何在Android中定期刷新数据?,android,Android,如果我使用了线程而不是异步任务,那么在活动中导航时如何定期刷新数据?我的数据在主活动中读取和解析 public class MainActivity extends Activity { //data_bedpres_future stores future data from current date public static ArrayList<ArrayList<String>> data_bedpres_future = new Arra

如果我使用了线程而不是异步任务,那么在活动中导航时如何定期刷新数据?我的数据在主活动中读取和解析

  public class MainActivity extends Activity
  {
    //data_bedpres_future stores future data from current date
    public static ArrayList<ArrayList<String>> data_bedpres_future = new ArrayList<ArrayList<String>>();

//data_bedpres_past stores past data from current date
public static ArrayList<ArrayList<String>> data_bedpres_past = new ArrayList<ArrayList<String>>();

//data_nyheter_future stores future data from current date
public static ArrayList<ArrayList<String>> data_nyheter_future = new ArrayList<ArrayList<String>>();

//data_nyheter_past stores past data from current date
public static ArrayList<ArrayList<String>> data_nyheter_past = new ArrayList<ArrayList<String>>();

private Handler mHandler = new Handler();
private ArrayList<Date> mydate = new ArrayList<Date>();

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

    final ProgressBar progress_waiting1=(ProgressBar)findViewById(R.id.progress1);
    progress_waiting1.setVisibility(ProgressBar.VISIBLE);


    final ProgressBar progress_waiting2=(ProgressBar)findViewById(R.id.progress2);
    progress_waiting2.setVisibility(ProgressBar.VISIBLE);

    Typeface tf_helvetica = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNw.ttf");
    Typeface tf_helvetica_bold = Typeface.createFromAsset(getAssets(),"fonts/HelveticaNwBd.ttf");

    Config.TF_HELVETICA=tf_helvetica;
    Config.TF_HELVETICA_BOLD=tf_helvetica_bold;



    final ImageButton bttn_bedpress=(ImageButton)findViewById(R.id.bttn_bedpress);
    ImageButton bttn_news=(ImageButton)findViewById(R.id.bttn_news);
    ImageButton bttn_logo=(ImageButton)findViewById(R.id.bttn_logo);
    ImageButton bttn_faq=(ImageButton)findViewById(R.id.bttn_faq);
    ImageButton bttn_cv=(ImageButton)findViewById(R.id.bttn_cv);
    ImageButton bttn_omnu=(ImageButton)findViewById(R.id.bttn_omnu);

    ImageButton bttn_recent=(ImageButton)findViewById(R.id.button1);

    final RelativeLayout img_gray_bg=(RelativeLayout)findViewById(R.id.img_gray_bg);
    img_gray_bg.setVisibility(ImageView.VISIBLE);

    final TextView txt_wait=(TextView)findViewById(R.id.txt_wait);
    txt_wait.setVisibility(TextView.VISIBLE);

    final TextView topheading=(TextView)findViewById(R.id.txt_topheading);
        topheading.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView headline=(TextView)findViewById(R.id.txt_headline);
        headline.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView date=(TextView)findViewById(R.id.txt_date);
        date.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView txt_place=(TextView)findViewById(R.id.txt_place);
        txt_place.setTypeface(Config.TF_HELVETICA_BOLD);
    final ImageView img_company=(ImageView)findViewById(R.id.img_company);

    final TextView txt_news=(TextView)findViewById(R.id.txt_news);
        txt_news.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView txt_career=(TextView)findViewById(R.id.txt_career);
        txt_career.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView txt_bedpress=(TextView)findViewById(R.id.txt_bedpress);
        txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD);

    final TextView txt_cv=(TextView)findViewById(R.id.txt_cv);
        txt_cv.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView txt_faq=(TextView)findViewById(R.id.txt_faq);
        txt_faq.setTypeface(Config.TF_HELVETICA_BOLD);
    final TextView txt_logo=(TextView)findViewById(R.id.txt_logo);
        txt_logo.setTypeface(Config.TF_HELVETICA_BOLD);

    if(!HaveNetworkConnection())
    {
        Log.v("no network","no network");
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Nettverk ikke tilgjengelig")
               .setCancelable(false)
               .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                   public void onClick(DialogInterface dialog, int id) 
                   {
                       dialog.cancel(); 
                   }
               });

        AlertDialog alert = builder.create();
        alert.show();
    }

    final Thread parseThread=new Thread(new Runnable() {

        public void run()
        {
            if(HaveNetworkConnection())
            {
                parseDataBedPres(Config.URL_BedPres);
                parseDataNyheter(Config.URL_Nyheter);
                Collections.sort(mydate);

            }
            else
            {
                Log.v("net not connected","net not connected");
                parseDataBedPresLocal();
                parseDataNyheterLocal();
                /*
                Looper.prepare();
                AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
                builder.setMessage("Nettverk ikke tilgjengelig")
                       .setCancelable(false)
                       .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) 
                           {
                               dialog.cancel(); 
                           }
                       });

                AlertDialog alert = builder.create();
                alert.show();*/
            }
        }
    });
    parseThread.start();

    Thread displayThread = new Thread(new Runnable() {
        public void run() {

         try
         {
             parseThread.join();
         }
         catch (InterruptedException e) 
         {
            e.printStackTrace();
         }  
         mHandler.post(new Runnable() { 
            public void run() 
            {
                // TODO Auto-generated method stub
                progress_waiting1.setVisibility(ProgressBar.GONE);
                progress_waiting2.setVisibility(ProgressBar.GONE);
                txt_wait.setVisibility(TextView.GONE);
                img_gray_bg.setVisibility(ImageView.GONE);

                String month[]=getResources().getStringArray(R.array.month_array);

                if(data_bedpres_future.size()!=0)
                {
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    Date dt = null;
                    Calendar cal = Calendar.getInstance();
                    try
                    {
                        dt = df.parse(data_bedpres_future.get(1).get(0));
                        cal.setTime(dt);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }

                    DateFormat df2=new SimpleDateFormat("hh:mm:ss");
                    Date dt2 = null;
                    Calendar cal2 = Calendar.getInstance();
                    try
                    {
                        dt2 = df2.parse(data_bedpres_future.get(2).get(0));
                        cal2.setTime(dt2);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }



                    date.setText("Tid: "+cal.get(Calendar.DATE)+" "+month[cal.get(Calendar.MONTH)]+" kl "+cal2.get(Calendar.HOUR_OF_DAY)+":"+cal2.get(Calendar.MINUTE));

                    //date.setText("Tid : "+data_bedpres_future.get(1).get(0));
                    headline.setText("Neste Bed.pres: "+data_bedpres_future.get(0).get(0));
                    txt_place.setText("Sted: "+data_bedpres_future.get(3).get(0));
                    try 
                    {

                            Drawable img = drawable_from_url(data_bedpres_future.get(4).get(0),"icon");
                            if(img!=null)
                            {
                                int height,width,w;
                                height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                                int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                                int wi    = (img.getMinimumWidth() * ratio) /100;
                                width = img.getMinimumWidth() -wi;
                                w=width;
                                int width1 = width > 211 ? 211 :width;
                                if (width>0) 
                                {
                                    ratio =  (((width - width1)*100)/width);
                                    int hi    = (height * ratio) /100;
                                    height = height -hi;
                                    w=width1;
                                }

                                ViewGroup.LayoutParams params = img_company.getLayoutParams();
                                params.height = height;
                                params.width = w;
                                img_company.setLayoutParams(params);
                                img_company.setBackgroundDrawable(drawable_from_url(data_bedpres_future.get(4).get(0),"icon"));
                            }

                    } catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }
                else if(data_nyheter_future.size()!=0)
                {
                    date.setText(data_nyheter_future.get(2).get(0));
                    headline.setText("Siste nyhet: "+data_nyheter_future.get(3).get(0));    


                    try 
                    {
                        Drawable img = drawable_from_url(data_nyheter_future.get(0).get(0),"icon");
                        if(img!=null)
                        {
                            int height,width,w;
                            height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                            int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                            int wi    = (img.getMinimumWidth() * ratio) /100;
                            width = img.getMinimumWidth() -wi;
                            w=width;
                            int width1 = width > 211 ? 211 :width;
                            if (width>0) 
                            {
                                ratio =  (((width - width1)*100)/width);
                                int hi    = (height * ratio) /100;
                                height = height -hi;
                                w=width1;
                            }

                            ViewGroup.LayoutParams params = img_company.getLayoutParams();
                            params.height = height;
                            params.width = w;
                            img_company.setLayoutParams(params);
                        img_company.setBackgroundDrawable(img);
                    } 
                    }catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }
                else if(data_nyheter_past.size()!=0)
                {
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    Date dt = null;
                    Calendar cal = Calendar.getInstance();
                    try
                    {
                        dt = df.parse(data_nyheter_past.get(2).get(0));
                        cal.setTime(dt);
                    }
                    catch (ParseException e1) 
                    {
                        e1.printStackTrace();
                    }
                    date.setText(""+cal.get(Calendar.YEAR)+"-"+month[cal.get(Calendar.MONTH)]+"-"+cal.get(Calendar.DATE));
                    headline.setText("Siste nyhet: "+data_nyheter_past.get(3).get(0));  

                    try 
                    {
                        Drawable img = drawable_from_url(data_nyheter_past.get(0).get(0),"icon");
                        if(img!=null)
                        {
                            int height,width,w;
                            height = img.getMinimumHeight() > 52 ? 52 :img.getMinimumHeight();
                            int ratio =  (((img.getMinimumHeight() - height)*100)/img.getMinimumHeight());
                            int wi    = (img.getMinimumWidth() * ratio) /100;
                            width = img.getMinimumWidth() -wi;
                            w=width;
                            int width1 = width > 211 ? 211 :width;
                            if (width>0) 
                            {
                                ratio =  (((width - width1)*100)/width);
                                int hi    = (height * ratio) /100;
                                height = height -hi;
                                w=width1;
                            }

                            ViewGroup.LayoutParams params = img_company.getLayoutParams();
                            params.height = height;
                            params.width = w;
                            img_company.setLayoutParams(params);
                        img_company.setBackgroundDrawable(img);
                    }
                    }
                    catch (MalformedURLException e) 
                    {
                        e.printStackTrace();
                    } catch (IOException e) 
                    {
                        e.printStackTrace();
                    }
                }
            }
        });

        }
    });
    displayThread.start();  

    bttn_bedpress.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            //bttn_bedpress.setBackgroundDrawable(getResources().getDrawable(R.drawable.bedpres_pressed));
            if(data_bedpres_future.size()!=0)
            {
                Log.v("size of future data","size="+data_bedpres_future.size());
                startActivity(new Intent("com.vyam.BusinessPresentations"));
            }
            else
            {
                startActivity(new Intent("com.vyam.BusinessPresentationsPast"));
            }
        }
    });

    bttn_news.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            if(data_nyheter_future.size()!=0)
            {
                Log.v("size of future data","size="+data_nyheter_future.size());
                startActivity(new Intent("com.vyam.FutureNews"));
            }
            else
            {
                startActivity(new Intent("com.vyam.PastNews"));
            }
        }
    });

    bttn_logo.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            startActivity(new Intent("com.vyam.CareerFair"));
        }
    });

    bttn_faq.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            startActivity(new Intent("com.vyam.FAQ"));
        }
    });

    bttn_cv.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            startActivity(new Intent("com.vyam.CV"));
        }
    });

    bttn_omnu.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            startActivity(new Intent("com.vyam.OmNU"));
        }
    });



    bttn_recent.setOnClickListener(new OnClickListener() {

        public void onClick(View v) 
        {
            Intent intent=new Intent("com.vyam.NewsDetail");
            intent.putExtra("type","past");//it sends information that data must be shown from data_bedpres_past
            intent.putExtra("position",0);
            startActivity(intent);
        }
    });

}

/**
 * the parseDataBedPres(String url)method does JSON parsing of  the url Config.URL_BedPres
 * @return void
 */ 

public void parseDataBedPres(String url)
{
    ArrayList<String> company_names_future = new ArrayList<String>();
    ArrayList<String> company_names_past = new ArrayList<String>();

    ArrayList<String> date_future = new ArrayList<String>();
    ArrayList<String> date_past = new ArrayList<String>();

    ArrayList<String> place_future = new ArrayList<String>();
    ArrayList<String> place_past = new ArrayList<String>();

    ArrayList<String> meeting_time_future = new ArrayList<String>();
    ArrayList<String> meeting_time_past = new ArrayList<String>();

    ArrayList<String> company_logo_future = new ArrayList<String>();
    ArrayList<String> company_logo_past = new ArrayList<String>();

    ArrayList<String> description_future = new ArrayList<String>();
    ArrayList<String> description_past = new ArrayList<String>();

    ArrayList<String> url_future = new ArrayList<String>();
    ArrayList<String> url_past = new ArrayList<String>();

    ArrayList<String> fb_id_future = new ArrayList<String>();
    ArrayList<String> fb_id_past = new ArrayList<String>();

    FileOutputStream fos=null;
    try {
        URL business_url = new URL(url);
        URLConnection tc = business_url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));


        StringBuffer fileData=new StringBuffer();

        String line;
        while ((line = in.readLine()) != null)
        {
            JSONArray ja = new JSONArray(line);
            Log.v("line"," "+line);

            fileData.append(line);

            for (int i = 0; i < ja.length(); i++) 
            {
                JSONObject jo = (JSONObject) ja.get(i);
                try
                {
                    Date today = new Date();
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm");
                    //Date date = df.parse(jo.getString("meeting_date"));
                    StringBuilder s1 = new StringBuilder(jo.getString("meeting_date"));
                      s1.append(" ");
                      s1.append(jo.getString("meeting_time"));
                      Date date = df.parse(s1.toString());

                    if(today.after(date))
                    {
                        if(jo.getString("company_name")!=null)
                            company_names_past.add(jo.getString("company_name"));
                        else
                            company_names_past.add(" ");
                        if(jo.getString("meeting_date")!=null)
                            date_past.add(jo.getString("meeting_date"));
                        else
                            date_past.add(jo.getString(" "));
                        if(jo.getString("meeting_address")!=null)
                            place_past.add(jo.getString("meeting_address"));
                        else
                            place_past.add(" ");
                        if(jo.getString("meeting_time")!=null)
                            meeting_time_past.add(jo.getString("meeting_time"));
                        else
                            meeting_time_past.add(jo.getString(" "));
                        if(jo.getString("company_logo")!=null)
                            company_logo_past.add(jo.getString("company_logo"));
                        else
                            company_logo_past.add(jo.getString(" "));
                        if(jo.getString("description")!=null)
                            description_past.add(jo.getString("description"));
                        else
                            description_past.add(jo.getString(" "));
                        if(jo.getString("company_url")!=null)
                            url_past.add(jo.getString("company_url"));
                        else
                            url_past.add(jo.getString(" "));
                        if(jo.getString("fb_event_id")!=null)
                            fb_id_past.add(jo.getString("fb_event_id"));
                        else
                            fb_id_past.add(jo.getString(" "));
                    }
                    else
                    {

                        if(jo.getString("company_name")!=null)
                            company_names_future.add(jo.getString("company_name"));
                        else
                            company_names_future.add(" ");
                        if(jo.getString("meeting_date")!=null)
                            date_future.add(jo.getString("meeting_date"));
                        else
                            date_future.add(jo.getString(" "));
                        if(jo.getString("meeting_address")!=null)
                            place_future.add(jo.getString("meeting_address"));
                        else
                            place_past.add(" ");
                        if(jo.getString("meeting_time")!=null)
                            meeting_time_future.add(jo.getString("meeting_time"));
                        else
                            meeting_time_future.add(jo.getString(" "));
                        if(jo.getString("company_logo")!=null)
                            company_logo_future.add(jo.getString("company_logo"));
                        else
                            company_logo_future.add(jo.getString(" "));
                        if(jo.getString("description")!=null)
                            description_future.add(jo.getString("description"));
                        else
                            description_future.add(jo.getString(" "));
                        if(jo.getString("company_url")!=null)
                            url_future.add(jo.getString("company_url"));
                        else
                            url_future.add(jo.getString(" "));
                        if(jo.getString("fb_event_id")!=null)
                            fb_id_future.add(jo.getString("fb_event_id"));
                        else
                            fb_id_future.add(jo.getString(" "));

                    }
                }
                catch (ParseException e)
                {
                      e.printStackTrace();
                }

            }
        }

        writeInternalStoragePrivate("BedPres",fileData.toString().getBytes());
    } 
    catch (MalformedURLException e) 
    {
        e.printStackTrace();
    } 
    catch (IOException e) 
    {
        e.printStackTrace();
    } 
    catch (JSONException e) 
    {
        e.printStackTrace();
    }



    if(company_names_future.size()!=0)
    {
        data_bedpres_future.add(company_names_future);
        data_bedpres_future.add(date_future);
        data_bedpres_future.add(meeting_time_future);
        data_bedpres_future.add(place_future);
        data_bedpres_future.add(company_logo_future);
        data_bedpres_future.add(description_future);
        data_bedpres_future.add(url_future);
        data_bedpres_future.add(fb_id_future);
    }
    if(company_names_past.size()!=0)
    {
        data_bedpres_past.add(company_names_past);
        data_bedpres_past.add(date_past);
        data_bedpres_past.add(meeting_time_past);
        data_bedpres_past.add(place_past);
        data_bedpres_past.add(company_logo_past);
        data_bedpres_past.add(description_past);
        data_bedpres_past.add(url_past);
        data_bedpres_past.add(fb_id_past);
    }

    Log.v("hello files----"," "+getFilesDir().getPath());

}


/**
 * This parses the url for Nyheter
 * @param url
 * @return 
 */
public void parseDataNyheter(String url)
{
    ArrayList<ArrayList<String>> data=new ArrayList<ArrayList<String>>();
    ArrayList<String> image1_future = new ArrayList<String>();
    ArrayList<String> image1_past = new ArrayList<String>();

    ArrayList<String> image2_future = new ArrayList<String>();
    ArrayList<String> image2_past = new ArrayList<String>();

    ArrayList<String> date_future = new ArrayList<String>();
    ArrayList<String> date_past = new ArrayList<String>();

    ArrayList<String> headline_future = new ArrayList<String>();
    ArrayList<String> headline_past = new ArrayList<String>();

    ArrayList<String> ingress_text_future = new ArrayList<String>();
    ArrayList<String> ingress_text_past = new ArrayList<String>();

    ArrayList<String> body_text_future = new ArrayList<String>();
    ArrayList<String> body_text_past = new ArrayList<String>();
    //ArrayList<Date> mydate = new ArrayList<Date>();


    FileOutputStream fos=null;
    try {
        URL business_url = new URL(url);
        URLConnection tc = business_url.openConnection();
        BufferedReader in = new BufferedReader(new InputStreamReader(tc.getInputStream()));

        StringBuffer fileData=new StringBuffer();

        String line;
        while ((line = in.readLine()) != null)
        {
            fileData.append(line);

            JSONArray ja = new JSONArray(line);
            Log.v("line"," "+line);

            for (int i = 0; i < ja.length(); i++) 
            {
                JSONObject jo = (JSONObject) ja.get(i);
                try
                {
                    Date today = new Date();
                    Log.v("todays date","date--"+today);
                    DateFormat df=new SimpleDateFormat("yyyy-MM-dd");
                    Date date1 = df.parse(jo.getString("date"));
                    if(today.after(date1))
                    {
                        if(jo.getString("image_1")!=null)
                            image1_past.add(jo.getString("image_1"));
                        else
                            image1_past.add(" ");
                        if(jo.getString("image_2")!=null)
                            image2_past.add(jo.getString("image_2"));
                        else
                            image2_past.add(" ");
                        if(jo.getString("date")!=null)
                            date_past.add(jo.getString("date"));
                        else
                            date_past.add(" ");
                        if(jo.getString("headline")!=null)
                            headline_past.add(jo.getString("headline"));
                        else
                            ingress_text_past.add(" ");
                        if(jo.getString("ingress_text")!=null)
                            ingress_text_past.add(jo.getString("ingress_text"));
                        else
                            headline_past.add(" ");
                        if(jo.getString("body_text")!=null)
                            body_text_past.add(jo.getString("body_text"));
                        else
                            body_text_past.add(" ");
                    }
                    else
                    {
                        if(jo.getString("image_1")!=null)
                            image1_future.add(jo.getString("image_1"));
                        else
                            image1_future.add(" ");
                        if(jo.getString("image_2")!=null)
                            image2_future.add(jo.getString("image_2"));
                        else
                            image2_future.add(" ");
                        if(jo.getString("date")!=null)
                            date_future.add(jo.getString("date"));
                        else
                            date_future.add(" ");
                        if(jo.getString("headline")!=null)
                            headline_future.add(jo.getString("headline"));
                        else
                            headline_future.add(" ");
                        if(jo.getString("ingress_text")!=null)
                            ingress_text_future.add(jo.getString("ingress_text"));
                        else
                            ingress_text_future.add(" ");
                        if(jo.getString("body_text")!=null)
                            body_text_future.add(jo.getString("body_text"));
                        else
                            body_text_future.add(" ");
                    }
                }
                catch (ParseException e)
                {
                      e.printStackTrace();
                }

            }
        }

        writeInternalStoragePrivate("Nyheter.txt",fileData.toString().getBytes());
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    if(headline_future.size()!=0)
    {
        data_nyheter_future.add(image1_future);
        data_nyheter_future.add(image2_future);
        data_nyheter_future.add(date_future);
        data_nyheter_future.add(headline_future);
        data_nyheter_future.add(ingress_text_future);
        data_nyheter_future.add(body_text_future);
    }
    if(headline_past.size()!=0)
    {
        data_nyheter_past.add(image1_past);
        data_nyheter_past.add(image2_past);
        data_nyheter_past.add(date_past);
        data_nyheter_past.add(headline_past);
        data_nyheter_past.add(ingress_text_past);
        data_nyheter_past.add(body_text_past);
    }


}
公共类MainActivity扩展活动
{
//data_bedpres_future存储当前日期的未来数据
public static ArrayList data_bedpres_future=new ArrayList();
//data_bedpres_past存储当前日期的过去数据
public static ArrayList data_bedpres_pass=new ArrayList();
//data_nyheter_future存储当前日期的未来数据
public static ArrayList data_nyheter_future=new ArrayList();
//data_nyheter_past存储当前日期的过去数据
public static ArrayList data_nyheter_pass=new ArrayList();
私有处理程序mHandler=新处理程序();
private ArrayList mydate=new ArrayList();
@凌驾
创建时受保护的void(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
最终进度条进度_waiting1=(进度条)findViewById(R.id.progress1);
progress_waiting1.setVisibility(ProgressBar.VISIBLE);
最终进度条进度_waiting2=(进度条)findViewById(R.id.progress2);
progress_waiting2.setVisibility(ProgressBar.VISIBLE);
Typeface tf_helvetica=Typeface.createFromAsset(getAssets(),“font/HelveticaNw.ttf”);
Typeface tf_helvetica_bold=Typeface.createFromAsset(getAssets(),“font/HelveticaNwBd.ttf”);
Config.TF_HELVETICA=TF_HELVETICA;
Config.TF_HELVETICA_BOLD=TF_HELVETICA_BOLD;
最终图像按钮bttn_床压=(图像按钮)findViewById(R.id.bttn_床压);
ImageButton BTTNU新闻=(ImageButton)findViewById(R.id.BTTNU新闻);
ImageButton bttn_徽标=(ImageButton)findViewById(R.id.bttn_徽标);
ImageButton bttn_faq=(ImageButton)findViewById(R.id.bttn_faq);
ImageButton bttn_cv=(ImageButton)findViewById(R.id.bttn_cv);
ImageButton bttn_omnu=(ImageButton)findViewById(R.id.bttn_omnu);
ImageButton bttn_最近=(ImageButton)findViewById(R.id.button1);
最终相对值img\u gray\u bg=(相对值)findViewById(R.id.img\u gray\u bg);
图像灰度背景设置可见性(ImageView.VISIBLE);
最终文本视图txt_wait=(文本视图)findViewById(R.id.txt_wait);
txt_wait.setVisibility(TextView.VISIBLE);
最终TextView topheading=(TextView)findViewById(R.id.txt_topheading);
topheading.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图标题=(文本视图)findViewById(R.id.txt_标题);
headline.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图日期=(文本视图)findViewById(R.id.txt\u日期);
日期设置字体(Config.TF_HELVETICA_BOLD);
最终文本视图txt_位置=(文本视图)findViewById(R.id.txt_位置);
txt_place.setTypeface(Config.TF_HELVETICA_BOLD);
最终ImageView img_公司=(ImageView)findViewById(R.id.img_公司);
最终文本视图txt_新闻=(文本视图)findViewById(R.id.txt_新闻);
txt_news.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图txt_职业=(文本视图)findViewById(R.id.txt_职业);
txt_career.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图txt_床压=(文本视图)findViewById(R.id.txt_床压);
txt_bedpress.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图txt_cv=(文本视图)findViewById(R.id.txt_cv);
txt_cv.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图txt_faq=(文本视图)findViewById(R.id.txt_faq);
txt_faq.setTypeface(Config.TF_HELVETICA_BOLD);
最终文本视图txt_徽标=(文本视图)findViewById(R.id.txt_徽标);
txt_logo.setTypeface(Config.TF_HELVETICA_BOLD);
如果(!HaveNetworkConnection())
{
Log.v(“无网络”、“无网络”);
AlertDialog.Builder=新建AlertDialog.Builder(此);
builder.setMessage(“nettwerk-ikke-tilgjengelig”)
.setCancelable(错误)
.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id)
{
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show();
}
final Thread parseThread=新线程(new Runnable()){
公开募捐
{
如果(HaveNetworkConnection())
{
parseDataBedPres(Config.URL\u BedPres);
parseDataNyheter(Config.URL\u Nyheter);
Collections.sort(mydate);
}
其他的
{
Log.v(“未连接网络”、“未连接网络”);
parseDataBedPresLocal();
parseDataNyheterLocal();
/*
Looper.prepare();
AlertDialog.Builder=新建AlertDialog.Builder(MainActivity.this);
builder.setMessage(“nettwerk-ikke-tilgjengelig”)
.setCancelable(错误)
.setPositiveButton(“确定”,新的DialogInterface.OnClickListener(){
public void onClick(DialogInterface对话框,int-id)
{
dialog.cancel();
}
});
AlertDialog alert=builder.create();
alert.show()*/
}
}
});
parseThread.start();
Thread displayThread=新线程(new Runnable(){
公开募捐{
尝试
{
parseThread.join();
}
捕捉(中断异常e)
{
e、 printStackTrace();
}  
mHandler.post(新的Runnable(){
公开募捐
{
//TODO自动生成的方法存根
progress_waiting1.setVisibility(ProgressBar.GONE);
进度\等待2.设置可见性(ProgressBar.GONE);
txt_wait.setVisibility(TextView.GONE);
图像灰度背景设置可见性(ImageView.GO
handler.post(runnable,1000);
private Runnable runnable = new Runnable(){
    public void run(){
       ........ ///do something
       handler.post(runnable,30000);
    }
}
handler.removeCallback(runnable);