getView Method & BaseAdapter..

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

getView Method & BaseAdapter..

Postby williamzanelli » Tue May 12, 2009 12:28 am

Hi guys,

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
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Reference

Postby satishkumar_lskin » Tue May 12, 2009 6:10 am

Hi,
Refer to DataSetObserver usage.
I suggest u have a look at the files ImageAdapter.java , ImageManager.java and other files if u need more clarity.

Regards
Satish
satishkumar_lskin
Developer
Developer
 
Posts: 32
Joined: Mon Oct 20, 2008 8:15 am
Location: Coimbatore , TamilNadu, India

Postby williamzanelli » Tue May 12, 2009 3:23 pm

Thanks for this Satish.

I've got ot to work...!

:D :D :D
Will
williamzanelli
Experienced Developer
Experienced Developer
 
Posts: 63
Joined: Mon Jan 05, 2009 2:37 am
Location: UK

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: Exabot [Bot] and 5 guests