views:

48

answers:

1

Hi, I'm writing an Android App that loads in data from an RSS Feed and lists the available items, and their description. There are 2 instances in which I use ArrayAdaptor. One works and one does not. The first one lists available feeds (right now the feed URLs are hard coded), and that one works. MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    this.setContentView(R.layout.main);

    UpdateDisplay();
}

private void UpdateDisplay()
{
    ListView itemlist = (ListView) findViewById(R.id.itemlist);
    java.util.ArrayList<String> channels = new java.util.ArrayList<String>();

    for(int i=0;i<RSS_FEEDS.length;i++){
        channels.add(RSS_FEEDS[i][0]);
    }

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, channels);
    itemlist.setAdapter(adapter);
    itemlist.setOnItemClickListener(this);
}

The second ArrayAdaptor is used in another Activity that the first generates by selecting a feed to view. The RSSFeed is parsed, and it returns valid data (I have tested it outside of teh android environment, and it worked, recompiled it in android, and it still works, so the RSSParser is not the issue). RSSFeed.java

public void onCreate(Bundle b){
    super.onCreate(b);

    setContentView(R.layout.feedlayout);

    UpdateDisplay();
}

private void UpdateDisplay()
{
    String feedUrl = null;

    Intent startingIntent = getIntent();
    if(startingIntent != null){
        Bundle args = startingIntent.getBundleExtra("android.intent.extra.INTENT");
        if(args != null){
            feedUrl = args.getString("URL");
            feedTitle = args.getString("title");
        }else{
            feedTitle = "No Available RSS Feed";
        }
    }else{
        feedTitle = "Error finding parent Intent";
    }

    ListView lv = (ListView)findViewById(R.id.storylist);

    if(feedUrl != null){
        // Get Feed Items
        RSSFeed feed = getFeed(feedUrl);

        ArrayList<String> values = loadItems(feed);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,values);

        lv.setAdapter(adapter);
        lv.setOnItemClickListener(this);
    }

    TextView title = (TextView)this.findViewById(R.id.feedtitle);
    title.setText(feedTitle);
    Button backbutton = (Button)findViewById(R.id.backbutton_2);
    backbutton.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View v) {
            finish();
        }
    });

}

I'm using the android.R.layout.simple_list_item_1 layout in both places, but it only works in the first. The backbutton Button also isn't displayed for some reason. Here's the feedlayout.xml file

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView
    android:id="@+id/feedtitle"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<ListView
    android:id="@+id/storylist"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    />
<Button
    android:id="@+id/backbutton_2"
    android:text="Back"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    />
</LinearLayout>
A: 

Sorry, I just realized that I misspelled Adapter. Anyway, I figured out the answer to my question, but I still can't see the back button , but I decided to remove it from the layout all together. I switched my Activity to a ListActivity, and that solved my problems, I just had to switch a couple function calls that are Activity dependent =)