列表在模拟器中清除,但在实际设备上不清除

时间:2010-03-05 11:23:49

标签: java android android-emulator

我遇到的问题是处理1.6设备的模拟器和实际1.6安卓设备(在这种情况下是T-mobile g1)的不同行为,当模拟器中的列表更新时,它会替换列表事先在那里。在电话上,它只是将新列表添加到旧列表的底部。

我需要设备的行为类似于模拟器。

非常感谢任何帮助。

import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;

import oauth.signpost.OAuthConsumer;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class timelineView extends ListActivity{

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

private String consumerKey;
private String consumerSecret;
private String accessKey;
private String accessSecret;
private Thread thread;
private imageLoader avatar;

private Bitmap picture;

private Timer timer = new Timer();

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.timeline);

    m_orders = new ArrayList<Order>();

    this.m_adapter = new OrderAdapter(this, R.layout.timeline_entry, m_orders);

    setListAdapter(this.m_adapter);

    refresher();
}
private Runnable returnRes = new Runnable() {

    public void run() {
        m_adapter.clear();
        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_adapter.notifyDataSetChanged();
    }
};
private void getOrders(ArrayList<Order> m_orders){

            String[][] resultOfTweet = new String[20][4];

            twitterHandeler sender = new twitterHandeler();

            consumerKey = "";
            consumerSecret = "";
            accessKey = "";
            accessSecret = "";

            OAuthConsumer consumer = sender.setConsumer(consumerKey, consumerSecret, accessKey, accessSecret);

            try {
                resultOfTweet = sender.getMentionTimeLine(consumer);
            } catch (OAuthMessageSignerException e) {
                // TODO Auto-generated catch block
                finish();
            } catch (OAuthExpectationFailedException e) {
                // TODO Auto-generated catch block
                finish();
            }


            int i = 0;

            do{
                Order o1 = new Order();
                o1.setOrderName(resultOfTweet[i][0]);
                o1.setOrderStatus(resultOfTweet[i][0] + "\n" + resultOfTweet[i][1]);

                avatar = new imageLoader();

                picture = avatar.imageLoaderer(resultOfTweet[i][3]);
                o1.setOrderPicture(picture);
                m_orders.add(o1);
                i++;
            }while(i < 20);

        runOnUiThread(returnRes);
    }
private class OrderAdapter extends ArrayAdapter<Order> {

    private ArrayList<Order> items = null;

    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.timeline_entry, null);
            }
            Order o = items.get(position);
            if (o != null){
                    TextView tt = (TextView) v.findViewById(R.id.topLine);
                    TextView bt = (TextView) v.findViewById(R.id.secondLine);
                    ImageView tv = (ImageView) v.findViewById(R.id.icons);
                    if (tt != null) {
                          tt.setText(o.getOrderName());                            }
                    if(bt != null){
                          bt.setText(o.getOrderStatus());
                    }
                    if(tv != null){
                        tv.setImageBitmap(o.getOrderPicture());
                  }
            }
            return v;
    }
}

private void refresher(){

    timer.scheduleAtFixedRate( new TimerTask() {
            public void run() {
                m_orders = new ArrayList<Order>();
                getOrders(m_orders);
            thread =  new Thread(null, viewOrders, "MagentoBackground");
            thread.start();
            } 
    }, 0, 30000);

    }
}

0 个答案:

没有答案