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!
Patrick
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();
}
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;
}
}
package nl.ipros.android.newsreader.util;
import java.util.List;
import nl.ipros.android.newsreader.R;
import android.content.Context;
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.LinearLayout;
import android.widget.TextView;
public class ArticleDetailAdapter extends ArrayAdapter {
private LayoutInflater mInflater;
private List Items;
@SuppressWarnings("unchecked")
public ArticleDetailAdapter(Context context, int textViewResourceId,
List Items) {
super(context,android.R.id.list,Items);
this.Items = Items;
Log.d("here", "ArticleDetailAdapter");
mInflater = LayoutInflater.from(context);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
Log.d("here", "Getview method loading");
// A ViewHolder keeps references to children views to avoid
unneccessary calls
// to findViewById() on each row.
ViewHolder holder;
// When convertView is not null, we can reuse it directly, there is
no need
// to reinflate it. We only inflate a new View when the convertView
supplied
// by ListView is null.
if (convertView == null){
convertView = mInflater.inflate(R.layout.article_row, null);
// Creates a ViewHolder and store references to the two children
views
// we want to bind data to.
holder = new ViewHolder();
holder.titleText = (TextView)
convertView.findViewById(R.id.article_title);
holder.descriptionText = (TextView)
convertView.findViewById(R.id.article_description);
//holder.icon = (ImageView)
convertView.findViewById(R.id.icon);
} else {
// Get the ViewHolder back to get fast access to the TextView
// and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
// Bind the data efficiently with the holder.
holder.titleText.setText((CharSequence) Items.get(position));
holder.descriptionText.setText("description");
//holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
return convertView;
}
static class ViewHolder {
TextView descriptionText;
TextView titleText;
ImageView icon;
}
}
--
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