I'm having som difficult getting me head round BaseAdapter.
I used Log.i to see how many times, getView is called - I found its called for every item in the list.
I have an arrayList that I want to display as a ListView - i want to use BaseAdapater as I want to use the method, notifyDataSetChanged to update the View via a Thread.
I also cant seem to get notifyDataSetChanged(); to work..
Can someone point me in the direction of a good tutorial.
Snippets of my code are liste below.
Can anyone see any deficiances in notifyDataSetChanged();?? Have I used it correctly?
- Code: Select all
public class List4 extends ListActivity {
//Vars listed here.
Handler myPizzaViewUpdateHandler = new Handler() {
public void handleMessage(Message msg) {
spa.setDataList(this.getData(url));
spa.notifyDataSetChanged();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
spa = new SpeechListAdapter(this);
spa.setDataList(this.getData(url));
setListAdapter(spa);
sc = new secondCountDownRunner();
this.myRefreshThread = new Thread(sc);
this.myRefreshThread.start();
}
class secondCountDownRunner implements Runnable {
public void run() {
while (!Thread.currentThread().isInterrupted()) {
List4.this.myPizzaViewUpdateHandler.sendMessage(m);
try {
Thread.sleep(30000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
public class SpeechListAdapter extends BaseAdapter {
private Context mContext;
public SpeechListAdapter(Context context) {
mContext = context;
if (dataList == null){
dataList = this.getData(url);
mTitles = (ArrayList) dataList;
}
}
public void setDataList(List mList){
mTitles = (ArrayList) mList;
}
public List getDataList(){
return mTitles;
}
public int getCount() {
return mTitles.size();
}
public Object getItem(int position) {
return getDataList().get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = new TextView(mContext);
tv.setText(mTitles.get(position) + "");
Log.i("View data added...", mTitles.get(position) + "");
return tv;
}
}
//Method getData implemented here
Thanks for your help in advance
Will


