coder_For_Life22
coder_For_Life22

Reputation: 26971

How to display items in a widget with a next button

I have a a list of items i want to display inside of a widget.

I was told that i should have a next button on the widget to show each item.

The question is i need to know how this works..Will each item be loaded as the user hits next?

I want the items to all load at once, and then the user be able to click through them with the next button..

Could some one give me greater detials on this? or an example or tutorial would be great.

Thanks

EDIT:

SO i have a list of Item Titles, and Some info about them loaded from html into an ArrayList.

What i want to do is display the items in a wigdet. ListView is not allowed in any os older then 3.0.

What is or how is the best way to get around this to display the items?

Upvotes: 0

Views: 129

Answers (1)

Codeman
Codeman

Reputation: 12375

You should create a custom UI component with everything you want the list item to contain.

Then inflate this item in a MyUIComponent.java class constructor, along with any listeners you need to register.

Use a ListAdapter to point all of these UI components stored in an array/List to to ListView.

This is how I did it in 2.2. Worked great!

Let me know if you need code.

EDIT:

Custom List adapter:

public class CatalogItemAdapter extends ArrayAdapter<Product> //
{
private ArrayList<Product> products;
private Activity activity;

public CatalogItemAdapter(Context context, int textViewResourceId,
        ArrayList<Product> items, Activity activity) //
{
    super(context, textViewResourceId, items);
    this.products = items;
    this.activity = activity;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) //
{
    Product product = products.get(position);

    if (convertView == null) //
    {
        LayoutInflater vi = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.catalog_item_stub, null, false);
            //this is the layout resource for each item
    }

    TextView priceView = (TextView) convertView
            .findViewById(R.id.ProductPrice);
    TextView titleView = (TextView) convertView
            .findViewById(R.id.ProductTitle);

    priceView.setText(price);
    titleView.setText(product.DisplayName);

    return convertView;
}
}

In your activity:

Call this to setup your List:

protected void setupUIElements(Activity activity) //
{

    listView = (ListView) activity.findViewById(R.id.CatalogProducts);

    m_adapter = new CatalogItemAdapter(activity,
            R.layout.catalog_item_stub, products, activity);

    listView.setAdapter(m_adapter);
}

Call this to fill the ListView with items:

void fillListView(final ProductResponse response) //
{
    for (Product p : response.Products) //
    {
        products.add(p);
    }
    progDialog.dismiss();
    m_adapter.notifyDataSetChanged();
}

Upvotes: 2

Related Questions