如何在适配器类中创建接口

时间:2016-04-15 10:40:15

标签: java android

我在适配器类中创建接口,但是它给了我这里预期接口的错误。我怎样才能在适配器类中实现接口。我制作了适配器和主类但是在这里显示了错误接口。 enter image description here

public class Dashboard_Adapter extends ArrayAdapter<Dashboard_Model_File>  implements RecyclerSwipeAdapter<Dashboard_Adapter.SimpleViewHolder>  {
    ArrayList<Dashboard_Model_File> dashboard_model_files_obj;

    LayoutInflater vi;
    int Resource;
    ViewHolder holder;

    public Dashboard_Adapter(Context context, int resource, ArrayList<Dashboard_Model_File> objects) {
        super(context, resource, objects);
        vi = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        Resource = resource;
        dashboard_model_files_obj = objects;
    }

    Typeface font1 = Typeface.createFromAsset(getContext().getAssets(), "fonts/cabin.regular.ttf");

    public static class SimpleViewHolder extends RecyclerView.ViewHolder {
        SwipeLayout swipeLayout;
        TextView textViewPos;
        TextView textViewData;
        Button buttonDelete;

        public SimpleViewHolder(View itemView) {
            super(itemView);
            swipeLayout = (SwipeLayout) itemView.findViewById(com.daimajia.swipe.R.id.swipe);
            textViewPos = (TextView) itemView.findViewById(com.daimajia.swipe.R.id.position);
            textViewData = (TextView) itemView.findViewById(com.daimajia.swipe.R.id.text_data);
            buttonDelete = (Button) itemView.findViewById(com.daimajia.swipe.R.id.delete);

            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.d(getClass().getSimpleName(), "onItemSelected: " + textViewData.getText().toString());
                    Toast.makeText(view.getContext(), "onItemSelected: " + textViewData.getText().toString(), Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    public Dashboard_Adapter(Dashboard dashboard, ArrayList<Dashboard_Model_File> dashboard_model_file_arraylist) {
        super();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent)
    {
        // convert view = design

        View v = convertView;
        if (v == null) {
            holder = new ViewHolder();
            v = vi.inflate(Resource, null);
            holder.imageview = (ImageView) v.findViewById(R.id.ivImage);
            holder.title_holder = (TextView) v.findViewById(R.id.title_view);
            holder.desc_holder = (TextView) v.findViewById(R.id.desc_view);
            holder.url_holder = (TextView) v.findViewById(R.id.url_view);

            holder.bookmark_id_holder = (TextView) v.findViewById(R.id.bookmark_id);
            holder.alternate_id_holder = (TextView) v.findViewById(R.id.alternate_id);
            holder.bookmark_file_holder = (TextView) v.findViewById(R.id.bookmark_file);
            holder.mode_holder = (TextView) v.findViewById(R.id.mode_id);

            holder.swipeLayout = (SwipeLayout) v.findViewById(com.daimajia.swipe.R.id.swipe);
            holder.textViewPos = (TextView) v.findViewById(com.daimajia.swipe.R.id.position);
            holder.textViewData = (TextView) v.findViewById(com.daimajia.swipe.R.id.text_data);
            holder.buttonDelete = (Button) v.findViewById(com.daimajia.swipe.R.id.delete);


            holder.title_holder.setTypeface(font1); holder.title_holder.setTextSize(16.0f);
            holder.desc_holder.setTypeface(font1); holder.desc_holder.setTextSize(14.0f);
            holder.url_holder.setTypeface(font1); holder.url_holder.setTextSize(10.0f);


            v.setTag(holder);
        } else {
            holder = (ViewHolder) v.getTag();
        }
        new DownloadImageTask(holder.imageview).execute(dashboard_model_files_obj.get(position).getImage());
        holder.title_holder.setText(dashboard_model_files_obj.get(position).getTitle());
        holder.desc_holder.setText(dashboard_model_files_obj.get(position).getDescription());
        holder.url_holder.setText(dashboard_model_files_obj.get(position).getUrl());

        return v;

    }

    private Context mContext;
    private ArrayList<String> mDataset;
    @Override
    public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(com.daimajia.swipe.R.layout.recyclerview_item, parent, false);
       return view;
    }

    @Override
    public void onBindViewHolder(final SimpleViewHolder viewHolder,final int position) {
        String item = mDataset.get(position);
        viewHolder.swipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
        viewHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {
            @Override
            public void onOpen(SwipeLayout layout) {
                YoYo.with(Techniques.Tada).duration(500).delay(100).playOn(layout.findViewById(com.daimajia.swipe.R.id.trash));
            }
        });
        viewHolder.swipeLayout.setOnDoubleClickListener(new SwipeLayout.DoubleClickListener() {
            @Override
            public void onDoubleClick(SwipeLayout layout, boolean surface) {
                Toast.makeText(mContext, "DoubleClick", Toast.LENGTH_SHORT).show();
            }
        });
        viewHolder.buttonDelete.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mItemManger.removeShownLayouts(viewHolder.swipeLayout);
                mDataset.remove(position);
                notifyItemRemoved(position);
                notifyItemRangeChanged(position, mDataset.size());
                mItemManger.closeAllItems();
                // Toast.makeText(view.getContext(), "Deleted " + viewHolder.textViewData.getText().toString() + "!", Toast.LENGTH_SHORT).show();
            }
        });
    }



    public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(com.daimajia.swipe.R.layout.recyclerview_item, parent, false);
        return new SimpleViewHolder(view);
    }



    @Override
    public int getItemCount() {
        return 0;
    }

    @Override
    public int getSwipeLayoutResourceId(int position) {
        return 0;
    }


    static class ViewHolder {
        public ImageView imageview;
        public TextView title_holder;
        public TextView desc_holder;
        public TextView url_holder;

        public TextView bookmark_file_holder;
        public TextView alternate_id_holder;
        public TextView bookmark_id_holder;
        public TextView mode_holder;

        public TextView txtCategory;

        SwipeLayout swipeLayout;
        TextView textViewPos;
        TextView textViewData;
        Button buttonDelete;

    }

    private class DownloadImageTask extends AsyncTask<String, Void, Bitmap>
    {
        ImageView bmImage;

        public DownloadImageTask(ImageView bmImage)
        {
            this.bmImage = bmImage;
        }

        protected Bitmap doInBackground(String... urls)
        {
            String urldisplay = urls[0];
            Bitmap mIcon11 = null;
            try {
                InputStream in = new java.net.URL(urldisplay).openStream();
                mIcon11 = BitmapFactory.decodeStream(in);
            } catch (Exception e) {
                Log.e("Error", e.getMessage());
                e.printStackTrace();
            }
            return mIcon11;
        }
        protected void onPostExecute(Bitmap result) {
            bmImage.setImageBitmap(result);
        }
    }


}

1 个答案:

答案 0 :(得分:0)

您正在尝试实现一个界面。并且根据错误,这个界面似乎不存在。