Android Programming Tutorials

(Romina) #1
Your Friends Seem Remote

new SharedPreferences.OnSharedPreferenceChangeListener() {
public void onSharedPreferenceChanged(SharedPreferences sharedPrefs, String
key) {
if (key.equals("user") || key.equals("password")) {
resetClient();
}
}
};


private IPostListener listener=new IPostListener.Stub() {
public void newFriendStatus(final String friend,
final String status,
final String createdAt) {
runOnUiThread(new Runnable() {
public void run() {
adapter.insert(new TimelineEntry(friend,
createdAt,
status), 0 );
}
});
}
};


class TimelineEntry {
String friend="";
String createdAt="";
String status="";


TimelineEntry(String friend, String createdAt,
String status) {
this.friend=friend;
this.createdAt=createdAt;
this.status=status;
}
}


class TimelineAdapter extends ArrayAdapter {
TimelineAdapter() {
super(Patchy.this, R.layout.row, timeline);
}


public^ View^ getView(int position, View convertView,
ViewGroup parent) {
View row=convertView;
TimelineEntryWrapper wrapper=null;


if (row==null) {
LayoutInflater inflater=getLayoutInflater();


row=inflater.inflate(R.layout.row, null);
wrapper=new TimelineEntryWrapper(row);
row.setTag(wrapper);
}
else {
wrapper=(TimelineEntryWrapper)row.getTag();


213
Free download pdf