在Listview中使用Horizo​​ntal Recyclerview

时间:2016-10-13 09:34:48

标签: android listview

我正在为Android TV开发一款应用。在我的应用程序中,需要使用类别名称显示视频缩略图类别。为了满足此要求,我使用Listview来显示类别明确的缩略图。在ListView中,每行包含一个显示类别名称的TextView和一个在水平方向上显示缩略图的Recyclerview。为了横向显示缩略图,我使用ImageButton来管理通过DPAD控制器的自动导航。当我按下DPAD UP和DOWN键时,所有工作正常,它从一个类别导航到另一个类别视频缩略图,当我按下左右DPAD键时它从一个缩略图导航到同一类别的另一个缩略图。但问题是它只能在可见的缩略图上导航。按下DPAD RIGHT键后选择最后一个缩略图后,水平Recyclerview不会滚动显示下一个缩略图。它仅在可见项目上向右或向左导航,我的要求是它应该导航特定类别的所有缩略图。请帮帮我.......

下面是我的活动代码,其中包含Listview

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home_screen_layout);

        verticalListView = (ListView)findViewById(R.id.category_listview);
        verticalListView.setItemsCanFocus(true);
        verticalListView.setDividerHeight(30);
        HomeCategoryListAdapter adapter = new HomeCategoryListAdapter(this,categoriesVideoList,categoryDataList);
        verticalListView.setAdapter(adapter);

下面是我的ListAdapter类

public class HomeCategoryListAdapter extends BaseAdapter {
    private Activity context;
    private ArrayList<ArrayList<VideoContentModel>> categoriesVideoList;
    private ArrayList<CategoryModel> categoryDataList;
    private LayoutInflater inflater = null;

    public HomeCategoryListAdapter(Activity context,
            ArrayList<ArrayList<VideoContentModel>> categoriesVideoList,
            ArrayList<CategoryModel> categoryDataList) {

        super();
        this.context = context;
        this.categoriesVideoList = categoriesVideoList;
        this.categoryDataList = categoryDataList;
        inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);


    }

    public int getCount() {

        return categoryDataList.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) 
{
        View vi=convertView;
        if(convertView==null)

            vi = inflater.inflate(R.layout.cat_name_vertical_row, null);
            RecyclerView recyclerView = (RecyclerView)vi.findViewById(R.id.horizontal_recyclerview);
            TextView cateTitleName = (TextView)vi.findViewById(R.id.cat_title_name);    

            cateTitleName.setText(categoryDataList.get(position).getCatTitle());
            LinearLayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false);
            recyclerView.setHasFixedSize(true);
            recyclerView.setLayoutManager(layoutManager);
            CategoryContentThumbnailAdapter adapter = new CategoryContentThumbnailAdapter(context,categoriesVideoList.get(position),
                    categoryDataList.get(position).getCatDfpTag());
            recyclerView.setAdapter(adapter);   

    return vi;
}
}

下面是Recyclerview适配器类

public class CategoryContentThumbnailAdapter extends
    RecyclerView.Adapter<CategoryContentThumbnailAdapter.MyViewHolder> {
Activity context;
int focusedItem = 0;
ArrayList<VideoContentModel> catVideoList;
String dfpTag;

public CategoryContentThumbnailAdapter(Activity context,ArrayList<VideoContentModel> catVideoList, String dfpTag) {
    super();
    this.context = context;
    this.catVideoList = catVideoList;
    this.dfpTag = dfpTag;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(context).inflate(R.layout.cat_row_thumbnail, parent, false);
    return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(MyViewHolder holder, int position) {
    VideoContentModel model = catVideoList.get(position);
    try {
        new com.calkins.imageloder.ImageLoader(context, 156, 1).DisplayImage(model.getVideoThumbnailUrl(),older.imageButton);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

@Override
public int getItemCount() {
    return catVideoList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
    ImageButton imageButton;
    public MyViewHolder(View itemView) {
        super(itemView);
        imageButton = (ImageButton) itemView
                .findViewById(R.id.cat_button_thumabnail);
    }

}

}

0 个答案:

没有答案
相关问题