2016-05-19 7 views
0

Ich möchte wissen, wie Sie das Argument an benutzerdefinierten Adapter übergeben. Ich versuche eine YouTube Videoliste mit listview + baseadapter zu implementieren. Ich bin nicht sicher, wie man richtig die Listenansicht zu bevölkern die baseadapter Mein Fehler mit ist:Konnte nicht aufgelöst werden Konstruktoradapter mit ListView mit Baseadapter

Error:(67, 39) error: constructor VideoListAdapter in class YouTubeVideo.VideoListAdapter cannot be applied to given types; 
required: Context 
found: YouTubeVideo,int,List<Video> 
reason: actual and formal argument lists differ in length 

Hier ist mein Code:

import android.content.Context; 
import android.os.Bundle; 
import android.support.v7.app.AppCompatActivity; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.ArrayAdapter; 
import android.widget.BaseAdapter; 
import android.widget.ListView; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.crashlytics.android.Crashlytics; 
import com.google.android.youtube.player.YouTubeApiServiceUtil; 
import com.google.android.youtube.player.YouTubeInitializationResult; 
import com.google.android.youtube.player.YouTubeThumbnailLoader; 
import com.google.android.youtube.player.YouTubeThumbnailView; 

import java.util.ArrayList; 
import java.util.HashMap; 
import java.util.List; 
import java.util.Map; 

import io.fabric.sdk.android.Fabric; 


public class YouTubeVideo extends AppCompatActivity { 

    public static List<Video> MyVideo = new ArrayList<Video>(); 
    public static Map<String, Video> Video_Map = new HashMap<>(); 

    private static void addItem(final Video currentVideo) { 
     MyVideo.add(currentVideo); 
     Video_Map.put(currentVideo.getVideoId(), currentVideo); 
    } 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_you_tube_video); 
     Fabric.with(this, new Crashlytics()); 

     //Check for any issues 
     final YouTubeInitializationResult result = YouTubeApiServiceUtil.isYouTubeApiServiceAvailable(this); 

     if (result != YouTubeInitializationResult.SUCCESS) { 
      //If there are any issues we can show an error dialog. 
      result.getErrorDialog(this, 0).show(); 
     } 

     populateVideoList(); 
     populateListView(); 
    } 

    private void populateVideoList() { 
     addItem(new Video("tttG6SdnCd4", "Open in the YouTube App")); 
     addItem(new Video("x-hH_Txxzls", "Open in the YouTube App in fullscreen")); 
     addItem(new Video("TTh_qYMzSZk", "Open in the Standalone player in fullscreen")); 
     addItem(new Video("tttG6SdnCd4", "Open in the Standalone player in \"Light Box\" mode")); 
     addItem(new Video("x-hH_Txxzls", "Open in the YouTubeFragment")); 
    } 

    private void populateListView() { 

     ArrayAdapter<Video> adapter = new VideoListAdapter(YouTubeVideo.this, R.layout.video_view, MyVideo); 
     ListView list = (ListView) findViewById(R.id.videoListView); 
     list.setAdapter(adapter); 
    } 
    //------------------------------------------------------------------------------------------------------------------- 12/05/16 
    private class VideoListAdapter extends BaseAdapter implements YouTubeThumbnailView.OnInitializedListener { 

     private Context mContext; 
     private Map<View, YouTubeThumbnailLoader> mLoaders; 

     public VideoListAdapter(final Context context) { 
      mContext = context; 
      mLoaders = new HashMap<>(); 
     } 

     @Override 
     public int getCount() { 
      return MyVideo.size(); 
     } 

     @Override 
     public Object getItem(int position) { 
      return MyVideo.get(position); 
     } 

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

     //------------------------------------------------------------------------------------------------------------------- 13/05/16 
     @Override 
     public View getView(int position, View convertView, ViewGroup parent) { 
      View videoRow = convertView; 

      VideoHolder holder; 

      final Video currentVideo = MyVideo.get(position); 


      if (videoRow == null) { 
       //Create the row 
       final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       videoRow = inflater.inflate(R.layout.video_view, parent, false); 

       //Create the video holder 
       holder = new VideoHolder(); 

       //Set the title 
       holder.title = (TextView) videoRow.findViewById(R.id.textView_title); 
       holder.title.setText(currentVideo.getVideoTitle()); 

       //Initialise the thumbnail 
       holder.thumb = (YouTubeThumbnailView) videoRow.findViewById(R.id.imageView_thumbnail); 
       holder.thumb.setTag(currentVideo.getVideoId()); 
       holder.thumb.initialize(mContext.getString(R.string.DEVELOPER_KEY), this); 

       videoRow.setTag(holder); 
      } else { 
       //Create it again 
       holder = (VideoHolder) videoRow.getTag(); 
       final YouTubeThumbnailLoader loader = mLoaders.get(holder.thumb); 

       //Set the title 
       if (currentVideo != null) { 
        holder.title.setText(currentVideo.getVideoTitle()); 

        if (loader == null) { 
         //Loader is currently initialising 
         holder.thumb.setTag(currentVideo.getVideoId()); 
        } else { 
         //The loader is already initialised 
         loader.setVideo(currentVideo.getVideoId()); 
        } 
       } 
      } 
      return videoRow; 
     } 

     @Override 
     public void onInitializationSuccess(YouTubeThumbnailView view, YouTubeThumbnailLoader loader) { 
      mLoaders.put(view, loader); 
      loader.setVideo((String) view.getTag()); 
     } 

     @Override 
     public void onInitializationFailure(YouTubeThumbnailView thumbnailView, YouTubeInitializationResult errorReason) { 
      final String errorMessage = errorReason.toString(); 
      Toast.makeText(mContext, errorMessage, Toast.LENGTH_LONG).show(); 
     } 

     private class VideoHolder { 
      YouTubeThumbnailView thumb; 
      TextView title; 
     } 

    } 
} 

Antwort

2

ich keinen Konstruktor in VideoListAdapter mit drei Parametern finden, ich glaube, Sie den folgenden Konstruktor verpasst in VideoListAdapter

public VideoListAdapter (Context context, int layoutResourceId, 
    List<Video> myvideos) { 
     super(activity, layoutResourceId, myvideos); 
     mContext = context; 
    } 

oder

ArrayAdapter<Video> adapter = new VideoListAdapter(YouTubeVideo.this, R.layout.video_view, MyVideo); 

mit

VideoListAdapter adapter = new VideoListAdapter(YouTubeVideo.this); 
+0

Sie haben Recht über den fehlenden Konstruktor, nur ein paar Korrekturen im Code vorgenommen. Vielen Dank – RCO

0

Es ist wirklich einfach ersetzen, es zu lösen;



    public VideoListAdapter (Context context, int layoutId, List lists) { 
     super(context); 
     mContext = context; 
     this.layoutId = layoutId; 
     this.lists = lists; 
    } 

viel glück!

Verwandte Themen