List clears in emulator but doesn't on an actual device
The problem I am having is with different behavior with dealing with the emulator of a 1.6 device and an actual 1.6 android device ( In this case a T-mobile g1 ), When the list updates in the emulator it replaces the list that was there beforehand. On the phone it just appends the new list onto the bottom of the old list.
I need the device to behave like the emulator .
Any help would be greatly appreciated.
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;
im开发者_运维技巧port 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);
}
}
精彩评论