[代码] [Java]代码
001 | package com.arg; |
002 | |
003 | import java.util.ArrayList; |
004 | |
005 | import android.app.ListActivity; |
006 | import android.app.ProgressDialog; |
007 | import android.content.Context; |
008 | import android.os.Bundle; |
009 | import android.util.Log; |
010 | import android.view.LayoutInflater; |
011 | import android.view.View; |
012 | import android.view.ViewGroup; |
013 | import android.widget.ArrayAdapter; |
014 | import android.widget.TextView; |
015 | |
016 | public class VprograssDialogActivity extends ListActivity { |
017 | private ProgressDialog m_ProgressDialog = null ; |
018 | private ArrayList m_orders = null ; |
019 | private OrderAdapter m_adapter; |
020 | private Runnable viewOrders; |
021 | |
022 | @Override |
023 | public void onCreate(Bundle savedInstanceState) { |
024 | super .onCreate(savedInstanceState); |
025 | setContentView(R.layout.main); |
026 | m_orders = new ArrayList(); |
027 | this .m_adapter = new OrderAdapter( this , R.layout.row, m_orders); |
028 | |
029 | setListAdapter( this .m_adapter); |
030 | |
031 | viewOrders = new Runnable(){ |
032 | @Override |
033 | public void run() { |
034 | getOrders(); |
035 | } |
036 | }; |
037 | Thread thread = new Thread( null , viewOrders, "MagentoBackground" ); |
038 | thread.start(); |
039 | m_ProgressDialog = ProgressDialog.show(VprograssDialogActivity. this , |
040 | "Please wait..." , "Retrieving data ..." , true ); |
041 | } |
042 | private Runnable returnRes = new Runnable() { |
043 | |
044 | @Override |
045 | public void run() { |
046 | if (m_orders != null && m_orders.size() > 0 ){ |
047 | m_adapter.notifyDataSetChanged(); |
048 | for ( int i= 0 ;i<m_orders.size();i++) |
049 | m_adapter.add(m_orders.get(i)); |
050 | } |
051 | m_ProgressDialog.dismiss(); |
052 | m_adapter.notifyDataSetChanged(); |
053 | } |
054 | }; |
055 | private void getOrders(){ |
056 | try { |
057 | m_orders = new ArrayList(); |
058 | Order o1 = new Order(); |
059 | o1.setOrderName( "SF services" ); |
060 | o1.setOrderStatus( "Pending" ); |
061 | Order o2 = new Order(); |
062 | o2.setOrderName( "SF Advertisement" ); |
063 | o2.setOrderStatus( "Completed" ); |
064 | m_orders.add(o1); |
065 | m_orders.add(o2); |
066 | Thread.sleep( 5000 ); |
067 | Log.i( "ARRAY" , "" + m_orders.size()); |
068 | } catch (Exception e) { |
069 | Log.e( "BACKGROUND_PROC" , e.getMessage()); |
070 | } |
071 | runOnUiThread(returnRes); |
072 | } |
073 | private class OrderAdapter extends ArrayAdapter{ |
074 | |
075 | private ArrayList items; |
076 | |
077 | public OrderAdapter(Context context, int textViewResourceId, ArrayList items) { |
078 | super (context, textViewResourceId, items); |
079 | this .items = items; |
080 | } |
081 | @Override |
082 | public View getView( int position, View convertView, ViewGroup parent) { |
083 | View v = convertView; |
084 | if (v == null ) { |
085 | LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE); |
086 | v = vi.inflate(R.layout.row, null ); |
087 | } |
088 | Order o = (Order) items.get(position); |
089 | if (o != null ) { |
090 | TextView tt = (TextView) v.findViewById(R.id.toptext); |
091 | TextView bt = (TextView) v.findViewById(R.id.bottomtext); |
092 | if (tt != null ) { |
093 | tt.setText( "Name: " +o.getOrderName()); } |
094 | if (bt != null ){ |
095 | bt.setText( "Status: " + o.getOrderStatus()); |
096 | } |
097 | } |
098 | return v; |
099 | } |
100 | } |
101 | } |
102 | |
103 | |
104 | Order.java |
105 | package com.arg; |
106 | |
107 | public class Order extends Object{ |
108 | private String orderName; |
109 | private String orderStatus; |
110 | public String getOrderName() { |
111 | return orderName; |
112 | } |
113 | public void setOrderName(String orderName) { |
114 | this .orderName = orderName; |
115 | } |
116 | public String getOrderStatus() { |
117 | return orderStatus; |
118 | } |
119 | public void setOrderStatus(String orderStatus) { |
120 | this .orderStatus = orderStatus; |
121 | } |
122 | |
123 | } |