2016-04-15 54 views
-7

我在適配器類中創建接口,但它給了我錯誤的接口,期望在這裏。如何在適配器類中實現接口。我做了適配器和主類,但顯示錯誤的接口預計在這裏。 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); 
     } 
    } 


} 
+2

更好職位的代碼,而不是抽點 – Raghunandan

+0

你很可能想實現一個類,而不是接口 –

+0

的主要問題是,你是太混合不同的適配器....的一個由RecyclerView使用和適配器視圖的一個userd (fx.ListView)...你不能同時使用... – Selvin

回答

0

你都賺不到的接口,你想實現一個。並根據錯誤,似乎這個接口不存在。