WearableListView错误

时间:2014-08-07 08:18:27

标签: java android wear-os

尝试为Google Play平台制作 可穿戴列表视图 在某些文档中,我读到有关创建WearalbleListView的文章,请阅读RecycleView。看完教程后我做了一些改动 多数民众赞成我的代码和2个错误。我该如何解决?

public class MyAdapter extends WearableListView.Adapter {

    private ItemData[] itemsData;
    public MyAdapter(ItemData[] itemsData) {
        this.itemsData = itemsData;
    }

    // Create new views (invoked by the layout manager)
    @Override
    public WearableListView.ViewHolder onCreateViewHolder(ViewGroup parent,
                                                   int viewType) {
        // create a new view
        View itemLayoutView = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.item_layout, null);

        // create ViewHolder

       ViewHolder viewHolder = new ViewHolder(itemLayoutView);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder( WearableListView.ViewHolder viewHolder, int position) {
    viewHolder.txtViewTitle.setText(itemsData[position].getTitle()); //Error
    viewHolder.imgViewIcon.setImageResource(itemsData[position].getImageUrl()); //Error

    }

    // inner class to hold a reference to each item of RecyclerView
    public static class ViewHolder extends WearableListView.ViewHolder {

        public TextView txtViewTitle;
        public ImageView imgViewIcon;

        public ViewHolder(View itemLayoutView) {
            super(itemLayoutView);
            txtViewTitle = (TextView)  itemLayoutView.findViewById(R.id.item_title);
            imgViewIcon  = (ImageView) itemLayoutView.findViewById(R.id.item_icon);
        }
    }

    // Return the size of your itemsData (invoked by the layout manager)
    @Override
    public int getItemCount() {
        return itemsData.length;
    }
}

UPD: 解决!

 @Override
    public void onBindViewHolder( WearableListView.ViewHolder viewHolder, int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        holder.txtViewTitle.setText(itemsData[position].getTitle());
        holder.imgViewIcon.setImageResource(itemsData[position].getImageUrl());

    }

0 个答案:

没有答案