0

I have pass from my MainFragment to my adapter list:

 viewModelAppe.getResponseLiveDataCombinedResult().observe(getActivity(),
                combinedResult -> mainAdapter.setProjectList(combinedResult.getArtistsWithPhoto()
                )) ;

my method in adaper:

private List<Pair<String,String>> localList  = Collections.emptyList();
public void setProjectList (final List<Pair<String,String>> list ){
    if (list != null){

        localList = list;
        notifyDataSetChanged();
    }else {
        Log.v("LOGer","isssue in adapter");
    }
}
  • my class CombinedResult

    public class CombinedResult {

    List<Pair<String,String>> perfectMapNameAndFoto;
    private final RootiTune ituneResult;
    private final RootLastFm lastFmResult;
    
    public CombinedResult(RootiTune ituneResult, RootLastFm lastFmResult) {
        this.ituneResult = ituneResult;
        this.lastFmResult = lastFmResult;
    }
    
    
    public List<Pair<String,String>> getArtistsWithPhoto ()
    {
        perfectMapNameAndFoto = new ArrayList<>() ;
    
    
        if (ituneResult.getListSongs() != null){
            for (ResultiTune item : ituneResult.getListSongs() ){
    
                perfectMapNameAndFoto.add(new Pair <String,String> (item.getArtistName(),item.getArtworkUrl100() ));
            }
        }
        if(lastFmResult.getResults().getArtistmatches().getListOfLatsFmArtists() != null) {
            for (ArtistLastFm item : lastFmResult.getResults().getArtistmatches().getListOfLatsFmArtists())
                perfectMapNameAndFoto.add(new Pair<String, String>(item.getName(), item.getUrl()));
        }
    
    
        return perfectMapNameAndFoto;
    
    }
    

    }

and method:

    @BindingAdapter("setName")
    public static void setName (@NonNull TextView textView, Pair <String,String> value, CombinedResult name){

        name.getArtistsWithPhoto();
        List<Pair<String, String>> valuePair = name.getArtistsWithPhoto();
        textView.setText(String.valueOf(valuePair));

}

Question:

my problem is that I dont know how to pull out data from first String

 List<Pair<String,String>

first String contain name that I want put in my textView at item_list in recyclerView, second is foto that in this case is irrelevant.

htw
  • 1,065
  • 7
  • 11
  • 1
    According to documentation https://developer.android.com/reference/android/util/Pair, use first and second properties to get parts of `Pair`. In your case to set artist name use `textView.setText(valuePair.first);` – ConstOrVar Nov 08 '18 at 20:48
  • How do you call `BindingAdapter` from layout? Can you show your requirement? – Khemraj Sharma Nov 12 '18 at 08:09
  • thanks for response ! I fix my issue by converting my List to List using Strem: List localArtistNameList = Stream.of(List).map(p -> p.first).collect(Collectors.toList()); – htw Nov 12 '18 at 08:29

0 Answers0