从List <pair <string,string >>的第一个值中拉出并在TextView上设置

时间:2018-11-08 20:15:40

标签: android android-databinding android-mvvm

我已经从MainFragment传递到了适配器列表:

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

我在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");
    }
}
  • 我的班级CombinedResult

    公共类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;
    
    }
    

    }

和方法:

    @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));

}

问题:

我的问题是我不知道如何从第一个字符串中提取数据

 List<Pair<String,String>

第一个字符串包含要在recyclerView的item_list中的textView中放置的名称,第二个是在这种情况下不相关的照片。

0 个答案:

没有答案