10秒自动后,Android ListView项变化? [英] Android Listview item Change after 10 seconds automatically?

查看:128
本文介绍了10秒自动后,Android ListView项变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个数组列表一个是departurelist,一个是到货清单我想说明这个名单

或者意味着10秒后列表自动更改

前10秒发车名单,未来10第二到达名单
我要将我的code在这里,我会尝试USINT可运行的,但我的应用程序是运行这个code时挂


  

首页activity.java


 最终诠释[] = sliderImageArray {R.drawable.banner,R.drawable.banner01,R.drawable.banner02};
        最终诠释[] = footerImageArray {R.drawable.bottomadv,R.drawable.sandwich,R.drawable.underbig};
        尝试
        {            Log.e(景观润,);
            Log.e(山水运行,处理程序);
                最后的处理程序imagehandler =新的处理程序();                可运行的可运行;                可运行=新的Runnable()
                {                    INT I = 0;
                    公共无效的run()
                    {//滑块映像运行
                        imageslider.setImageResource(sliderImageArray [I]); //Log.e(\"Image运行,+ sliderImageArray [I]);
                        我++;
                        如果(ⅰ> sliderImageArray.length-1)
                        {
                                I = 0;
                                明确();
                        }
                        imagehandler.postDelayed(此,4000); //区间
                    }                };
                imagehandler.postDelayed(可运行,10);                最后的处理程序footerimagehandler =新的处理程序();
                可运行=新的Runnable()
                {
                    INT J = 0;
                    公共无效的run()
                    {//页脚影像奔跑
                        imagefooter.setImageResource(footerImageArray [J]); // Log.e(图像运行,+ footerImageArray [J]);
                        J ++;
                        如果(J> footerImageArray.length-1)
                        {
                                J = 0;
                                明确();
                        }
                        footerimagehandler.postDelayed(这一点,5000); //区间
                    }
                };                footerimagehandler.postDelayed(可运行,10);
                // 10秒后,ListView的变化;
                最后的处理程序listhandler =新的处理程序();
                可运行=新的Runnable(){                    公共无效的run(){
                        //离境航班列表                                如果(!fl​​ightList.isEmpty())
                                {
                                        INT DISPLAYMODE = getResources()getConfiguration()方向。;
                                        如果(DISPLAYMODE == 1)
                                        {
                                                textviewinfo.setText(离境航班表);
                                                ListAdapter适配器=新SimpleAdapter(HomeActivity.this,flightList,
                                                        R.layout.listportrait,
                                                        新的String [] {TAG_MDESTINATION,TAG_MFLIGHT,TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS},新的INT [] {
                                                                R.id.textdestination,R.id.textflight,R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus});
                                                setListAdapter(适配器);                                        }
                                        其他
                                        {
                                               textviewcity.setText(textcity);
                                               textviewairport.setText(textairport);
                                               textviewinfo.setText(离境航班表);                                            ListAdapter适配器=新SimpleAdapter(HomeActivity.this,flightList,
                                                    R.layout.list,
                                                    新的String [] {TAG_MDESTINATION,TAG_MFLIGHT,TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS},新的INT [] {
                                                            R.id.textdestination,R.id.textflight,R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus});
                                            setListAdapter(适配器);                                        }
                                } listhandler.postDelayed(这一点,1000); //如果循环完全背离
                            //港航班列表
                                如果(!arrivalList.isEmpty())
                                {                                        INT DISPLAYMODE = getResources()getConfiguration()方向。;
                                        如果(DISPLAYMODE == 1)
                                        {
                                            text1.setText(原点);
                                            text4.setText(到达);
                                            textviewinfo.setText(抵达航班表);                                                ListAdapter适配器=新SimpleAdapter(HomeActivity.this,arrivalList,
                                                        R.layout.listportrait,
                                                        新的String [] {TAG_MDESTINATION,TAG_MFLIGHT,TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS},新的INT [] {
                                                                R.id.textdestination,R.id.textflight,R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus});
                                                setListAdapter(适配器);                                        }
                                        其他
                                        {
                                                text1.setText(原点);
                                                text4.setText(到达);
                                                textviewinfo.setText(抵达航班表);                                            ListAdapter适配器=新SimpleAdapter(HomeActivity.this,arrivalList,
                                                    R.layout.list,
                                                    新的String [] {TAG_MDESTINATION,TAG_MFLIGHT,TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS},新的INT [] {
                                                            R.id.textdestination,R.id.textflight,R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus});
                                            setListAdapter(适配器);                                        }
                                } listhandler.postDelayed(这一点,100); //如果完全arrrival                    }
                };
                listhandler.postDelayed(可运行,10);


解决方案

 处理程序处理程序=新的处理程序();handler.postDelayed(新的Runnable(){
@覆盖
公共无效的run(){//做任何事情
}
},10000);

这code几乎是一样的。你可以尝试创建两个10秒的延迟

方法递归调用

i have two arraylist one is departurelist and one is arrival list i want to show this list

alternatively means after 10 seconds list is change automatically

first 10 seconds departure list and next 10 second arrival list i will put my code here i will try usint runnable but my apps is hang when run this code

Home activity.java

  final int []sliderImageArray={R.drawable.banner,R.drawable.banner01,R.drawable.banner02};
        final int []footerImageArray={R.drawable.bottomadv,R.drawable.sandwich,R.drawable.underbig};
        try 
        {

            Log.e("Land Scape Run","");
            Log.e("LandScape  Run","Handler ");
                final Handler imagehandler = new Handler();

                Runnable runnable;

                runnable = new Runnable()
                {

                    int i=0;
                    public void run()
                    {   // slider image run
                        imageslider.setImageResource(sliderImageArray[i]);  //Log.e("Image Run",""+sliderImageArray[i]);
                        i++;
                        if(i>sliderImageArray.length-1)
                        {
                                i=0;    
                                clear();
                        }
                        imagehandler.postDelayed(this, 4000); // for interval
                    }

                };
                imagehandler.postDelayed(runnable,10);

                final Handler footerimagehandler =new Handler();
                runnable = new Runnable()
                {   
                    int j=0;
                    public void run()
                    {   // footer image run
                        imagefooter.setImageResource(footerImageArray[j]); //   Log.e("Image Run",""+footerImageArray[j]);
                        j++;
                        if(j>footerImageArray.length-1)
                        {
                                j=0;    
                                clear();
                        }
                        footerimagehandler.postDelayed(this, 5000); // for interval
                    }
                };

                footerimagehandler.postDelayed(runnable, 10);


                // For ListView Change after 10 seconds;
                final Handler listhandler= new Handler();
                runnable = new Runnable() {

                    public void run() {
                        // departure flight list

                                if(!flightList.isEmpty())
                                {
                                        int displaymode=getResources().getConfiguration().orientation;
                                        if(displaymode==1)
                                        {
                                                textviewinfo.setText("Departure Flight List");
                                                ListAdapter adapter = new SimpleAdapter(HomeActivity.this,flightList,
                                                        R.layout.listportrait,
                                                        new String[] { TAG_MDESTINATION, TAG_MFLIGHT, TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS  }, new int[] {
                                                                R.id.textdestination, R.id.textflight, R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus });
                                                setListAdapter(adapter);

                                        }
                                        else
                                        {
                                               textviewcity.setText(textcity);
                                               textviewairport.setText(textairport);
                                               textviewinfo.setText("Departure Flight List");

                                            ListAdapter adapter = new SimpleAdapter(HomeActivity.this,flightList,
                                                    R.layout.list,
                                                    new String[] { TAG_MDESTINATION, TAG_MFLIGHT, TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS  }, new int[] {
                                                            R.id.textdestination, R.id.textflight, R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus });
                                            setListAdapter(adapter);

                                        }
                                }listhandler.postDelayed(this,1000);// if loop complete departure
                            // arrival flight list
                                if(!arrivalList.isEmpty())
                                {

                                        int displaymode=getResources().getConfiguration().orientation;
                                        if(displaymode==1)
                                        {
                                            text1.setText("Origin");
                                            text4.setText("Arrival");
                                            textviewinfo.setText("Arrival Flight List");

                                                ListAdapter adapter = new SimpleAdapter(HomeActivity.this,arrivalList,
                                                        R.layout.listportrait,
                                                        new String[] { TAG_MDESTINATION, TAG_MFLIGHT, TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS  }, new int[] {
                                                                R.id.textdestination, R.id.textflight, R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus });
                                                setListAdapter(adapter);

                                        }
                                        else
                                        {
                                                text1.setText("Origin");
                                                text4.setText("Arrival");
                                                textviewinfo.setText("Arrival Flight List");

                                            ListAdapter adapter = new SimpleAdapter(HomeActivity.this,arrivalList,
                                                    R.layout.list,
                                                    new String[] { TAG_MDESTINATION, TAG_MFLIGHT, TAG_MAIRLINE,TAG_MSCHEDULE,TAG_MTERMINALGATE,TAG_MFSTATUS  }, new int[] {
                                                            R.id.textdestination, R.id.textflight, R.id.textairline,R.id.textschedule,R.id.texttermgate,R.id.textstatus });
                                            setListAdapter(adapter);

                                        }
                                }listhandler.postDelayed(this,100);// if complete arrrival

                    }
                };
                listhandler.postDelayed(runnable, 10);

解决方案

Handler handler = new Handler();

handler.postDelayed(new Runnable() {
@Override
public void run() {

//do anything


}
}, 10000);

this code is almost same. you can try to create a 'recursive call' of both the methods with a delay of 10 seconds

这篇关于10秒自动后,Android ListView项变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆