gpt4 book ai didi

java - Listview order.runOnUiThread?

转载 作者:行者123 更新时间:2023-12-01 13:08:20 24 4
gpt4 key购买 nike

大家好,我的 ListView 有问题...这是我的代码:

     private ArrayAdapter<String> adapter ;  

private ProgressDialog m_ProgressDialog = null;
private ArrayList<Order> m_orders = null;
public OrderAdapter m_adapter;
private Runnable viewOrders;

public class Order {

private String orderName;
private String orderStatus;

public String getOrderName() {
return orderName;
}
public void setOrderName(String orderName) {
this.orderName = orderName;
}
public String getOrderStatus() {
return orderStatus;
}
public void setOrderStatus(String orderStatus) {
this.orderStatus = orderStatus;
}
}
private class OrderAdapter extends ArrayAdapter<Order> {

private ArrayList<Order> items;

public OrderAdapter(Context context, int textViewResourceId, ArrayList<Order> items) {
super(context, textViewResourceId, items);
this.items = items;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.list_single, null);
}
Order o = items.get(position);
if (o != null) {
// TextView tv2 = (TextView) v.findViewById(R.id.tv2);
TextView tv1 = (TextView) v.findViewById(R.id.tv1); //codice volo
TextView tv2 = (TextView) v.findViewById(R.id.tv2); // citta

TextView tv5 = (TextView) v.findViewById(R.id.tv5); //stato volo
TextView tv6 = (TextView) v.findViewById(R.id.tv6); //ora prevista
TextView tv7 = (TextView) v.findViewById(R.id.tv7); //ora stimata if (tt != null) {

tv1.setText("VOLO: "+o.getOrderName());
}
return v;
}
}

private void getOrders(){
try{
m_orders = new ArrayList<Order>();
Order o1 = new Order();
o1.setOrderName("SF services");
o1.setOrderStatus("Pending");
Order o2 = new Order();
o2.setOrderName("SF Advertisement");
o2.setOrderStatus("Completed");
m_orders.add(o1);
m_orders.add(o2);
Thread.sleep(2000);
Log.i("ARRAY", ""+ m_orders.size());
} catch (Exception e) {
Log.e("BACKGROUND_PROC", e.getMessage());
}
runOnUiThread(returnRes);
}
public LayoutInflater getSystemService(String layoutInflaterService) {
// TODO Auto-generated method stub
return null;
}

private Runnable returnRes = new Runnable() {

@Override
public void run() {
if(m_orders != null && m_orders.size() > 0){
m_adapter.notifyDataSetChanged();
for(int i=0;i<m_orders.size();i++)
m_adapter.add(m_orders.get(i));
}
m_ProgressDialog.dismiss();
m_adapter.notifyDataSetChanged();
}
};

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

View ios = inflater.inflate(R.layout.arrivi, container, false);


m_orders = new ArrayList<Order>();
this.m_adapter = new OrderAdapter(getActivity(), R.layout.list_single, m_orders);
setListAdapter(getActivity(),m_adapter);

viewOrders = new Runnable(){
@Override
public void run() {
getOrders();
}
};
Thread thread = new Thread(null, viewOrders, "MagentoBackground");
thread.start();
m_ProgressDialog = ProgressDialog.show(getActivity(),
"Please wait...", "Retrieving data ...", true);

// new MyTask().execute("");
return ios;

}


private void setListAdapter(FragmentActivity activity,
OrderAdapter m_adapter2) {
// TODO Auto-generated method stub

}

在 Eclipse 中我收到此错误:类型 arrivi 的 runOnUiThread(Runnable) 方法未定义此代码不在 MainActivity 中,而是在名为 arrivi 的 fragment 中。文件 XML 是 list_single.xml 并且与自定义行关联!你能帮我一下吗?

还有一个问题...如何实现AsyncTask来替代Thread

public class MyTask extends AsyncTask<String, Void, String> {
ProgressDialog prog;
String info;

...当我运行我的应用程序时...它在“检索数据...”中循环非常感谢!!

最佳答案

runOnUiThread 是 Activity 的方法子类。 fragment 内部:

getActivity().runOnUiThread(runnable);

关于java - Listview order.runOnUiThread?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23096116/

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