gpt4 book ai didi

Android Listview 项目在 10 秒后自动更改?

转载 作者:太空宇宙 更新时间:2023-11-03 12:59:34 24 4
gpt4 key购买 nike

我有两个数组列表,一个是出发列表,一个是到达列表我想显示这个列表

或者表示 10 秒后列表自动更改

前 10 秒出发列表和后 10 秒到达列表我会把我的代码放在这里我会尝试使用 usint runnable 但我的应用程序在运行此代码时挂起

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);

这段代码几乎是一样的。您可以尝试创建延迟 10 秒的两种方法的“递归调用

关于Android Listview 项目在 10 秒后自动更改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13854955/

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