Patrick Plaatje wrote:
> Hi All,
> 
> Struggling and struggling, but can't find the thing i'm doin wrong in my
> listview implementation. No exceptions, just no listview. I have a
> customized adapter with an overridden getView method, but the Log.d
> won't show, so i guess my adapter is just wrong? Could somebody have a
> look at the code below? Thanks in advance!

<snip>

> public class ArticleList extends ListActivity {
>    
>     /** Called when the activity is first created. */
>     public void onCreate(Bundle savedInstanceState) {
>         // call super constructor
>         super.onCreate(savedInstanceState);
>        
>         // set the layout used for this activity
>         setContentView(R.layout.article_list);
>        
>         // create a new splashscreen and show it:
>         SplashScreen ss = new SplashScreen(this);
>         ss.show();
>        
>         // now that we have the splash screen displayed fire up the
>         // method that's going to fetch our content
>         ArticleListView alv = new ArticleListView(this);
>         alv.setSource("rss");
>         alv.show();
>         ss.hide();
> }

Your splash screen will never be shown, since you hide it before it is
displayed. Remember that nothing you do in onCreate(), or any callback,
will affect the screen until *after* the callback returns.

If you are eventually going to do a real implementation of this, with
HTTP retrieval of a feed, you are going to need to rework this code to
take threading into account. You will not be successful retrieving a
feed on the main application thread, as you will take too long and get
the fabled "application not responding" (ANR) force-close dialog. You
will need to do the retrieval in a background operation, perhaps using
an AsyncTask.

> public class ArticleListView {
>    
>     private String source=null;
>     private ListView lv;
>    
>     public ArticleListView(ListActivity act) {
>        
>         // find the list view
>         lv = (ListView) act.findViewById(android.R.id.list);
>        
>         // get the messages
>         FeedManager fm = new FeedManager();
>         Feed f = fm.getFeed("Some valid feed url");
>         List<FeedMessage> messages = f.getMessages();
>        
>         // get the adapter for the list
>         ArticleDetailAdapter adp = new ArticleDetailAdapter(act,
> android.R.layout.simple_list_item_2, messages);
>        
>         lv.setAdapter(adp);
> 
>     }
>    
>     public void show(){
>         lv.setVisibility(View.VISIBLE);
>     }
>    
>     public void hide(){
>         lv.setVisibility(View.GONE);
>     }
>    
>     public void setSource(String source){
>         this.source = source;
>     }
>    
>     public String getSource(){
>         return source;
>     }
>    
> }

You could use hierarchyviewer to see if your ListView is actually
becoming visible. You could also check to see that f.getMessages() will
return a non-empty list -- if the list is empty, getView() will not be
called for any rows.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android Training in Germany, 18-22 January 2010: http://bignerdranch.com

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to