0
最初我的應用程序顯示5個相對佈局。如果您單擊相對佈局,則加載線性佈局;此時我想顯示進度條。進度條問題
我用進度條下面的代碼,但我得到異常 >android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
我如何處理呢?
代碼
private OnClickListener exit1Listener = new OnClickListener()
{
public void onClick(View v)
{
if(!exit1status)
{
System.out.println("exit1 visible");
// Exit1 Restaurants
if(RB_Constant.upcomingexits_obj.response.size() > 0)
{ i if(RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size() > 0)
{
//YRS: listview1.setAdapter(new UpcomingResultsListViewAdapter1(this));
// Create the views on the fly instead of using the ListView
rbupcadapter1 = new UpcomingResultsListViewAdapter1(RB_UpcomingExits.this);
if(RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size() > 0)
{
numItems1 = RB_Constant.upcomingexits_obj.response.get(0).listRestaurants.size();
}
Exitexpand_pd = ProgressDialog.show(RB_UpcomingExits.this, "", "Please wait...", true);
Thread t = new Thread()
{
public void run()
{
try
{
for(position=0; position < numItems1; position++)
{
View convertview = null;
convertview = rbupcadapter1.getView(position, convertview, null); listLayout1.addView(convertview);
}
}
catch(Exception e)
{ System.out.println("Exit1Listener error ->"+e.toString());
} rb_Exitexpand_Handler.post(null);
Exitexpand_pd.dismiss();
}
};
t.start();
//listview1.setMinimumHeight(2000);
}
}
else{
//toastMsg("No results!");
}
listLayout1.setVisibility(View.VISIBLE);
exit1status = true;
if(exit2status || exit3status || exit4status || exit5status)
{
//System.out.println("exit2 GONE");
listLayout2.setVisibility(View.GONE);
listLayout3.setVisibility(View.GONE);
listLayout4.setVisibility(View.GONE);
listLayout5.setVisibility(View.GONE);
}
}
else
{
System.out.println("exit1 GONE");
listLayout1.setVisibility(View.GONE);
exit1status = false;
}
}
};
這裏我使用這個處理程序的代碼rb_Exitexpand_Handler.post(null); – naresh
這意味着我在這裏調用其他視圖,然後添加到線程內的線性佈局。我想你說過這是問題。 – naresh
如何實現處理程序對象? – naresh