我有一个要在小部件内显示的项目列表。
我被告知我应该在小部件上有一个下一个按钮来显示每个项目。
问题是我需要知道它是如何工作的。当用户点击下一个项目时,是否会加载每个项目?
我希望所有项目都能一次加载,然后用户可以使用下一个按钮点击它们。
有人可以给我更大的贬值吗?或者一个例子或教程会很棒。
由于
编辑:
我有一个项目标题列表,有关它们的一些信息从html加载到ArrayList中。
我想要做的是在wigdet中显示项目。 任何超过3.0的操作系统都不允许使用ListView。
解决此问题的最佳方式是什么或如何显示项目?
答案 0 :(得分:2)
您应该创建一个自定义UI组件,其中包含您希望列表项包含的所有内容。
然后在MyUIComponent.java类构造函数中填充此项目,以及需要注册的任何侦听器。
使用ListAdapter将存储在数组/列表中的所有这些UI组件指向ListView。
这就是我在2.2中所做的。工作得很好!
如果您需要代码,请告诉我。
编辑:
自定义列表适配器:
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;
}
}
在您的活动中:
调用此方法设置您的列表:
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);
}
调用此方法以使用项目填充ListView:
void fillListView(final ProductResponse response) //
{
for (Product p : response.Products) //
{
products.add(p);
}
progDialog.dismiss();
m_adapter.notifyDataSetChanged();
}