0

私はタブレイアウト&と一緒に作業しています。ViewPager with Fragment Android(Func <T,T,T> Java(Android)の代わり)

私はXamarin Android用プロジェクトを開発しましたが、今はAndroid Studioで作成したいと考えています。

私は以前のプロジェクトと同じFragmentPagerAdapterを実装しましたが、問題はFragmentクラスのFuncを使用しています。

私のかつてのクラスは、このようなものでした:

public class SelectDateViewFragment : Android.Support.V4.App.Fragment 
{ 
    readonly Func<LayoutInflater, ViewGroup, Bundle, View> view; 

    public SelectDateViewFragment(Func<LayoutInflater, ViewGroup, Bundle, View> _view) 
    { 
     view = _view; 
    } 

    public override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 

     // Create your fragment here 
    } 

    public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     // Use this to return your custom view for this Fragment 
     // return inflater.Inflate(Resource.Layout.YourFragment, container, false); 
     base.OnCreateView(inflater, container, savedInstanceState); 
     return view(inflater, container, savedInstanceState); 
    } 
} 

そして、私はフラグメントを作成し、このようFragmentListに追加することができた:

viewPagerAdapter.addFragmentView((i, v, b) => 
       { 
        var view = i.Inflate(Resource.Layout.SelectDateRecyclerViewLayout, v, false); 

だから、あなたが使用できるようにするには何をお勧めします私の活動の中で同じ論理ですか?

ありがとうございました。

+1

コードの画像を投稿しないでください。 '{} 'ボタンを使用して書式設定されたコードをテキストとして投稿します。 – Blorgbeard

+0

@Blorgbeard完了、ありがとうございます。 – user3817558

答えて

0

問題は解決しました。

基本的には、必要なパラメータを使ってFunc to Javaを実装しました。フラグメントのインタフェース

public interface Func<B,N,K, View> { 
View invoke(B arg1,N arg2,K arg3); 

}

2)実装インタフェース

class FuncImpl<B,N,K, View> implements Func<B,N,K, View> { 
Func<B,N,K, View> function; 
public FuncImpl(Func<B,N,K, View> function) { 
    this.function = function; 
} 
@Override 
public View invoke(B arg1,N arg2,K arg3) { 
    return this.function.invoke(arg1, arg2, arg3); 
}} 

3)を使用してクラスを作成する

1)

public class SelectDateViewFragment extends Fragment { 

Func<LayoutInflater,ViewGroup,Bundle,View> view; 

public SelectDateViewFragment(Func<LayoutInflater,ViewGroup,Bundle,View> view){ 
    this.view = view; 
} 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
} 

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    super.onCreateView(inflater, container, savedInstanceState); 

    return view.invoke(inflater,container,savedInstanceState); 

}} 

4)ViewPagerアダプタを設定します

selectDateAdapter = new SelectDateAdapter(getSupportFragmentManager(),charSequences); 

    selectDateAdapter.addFragmentView(new Func<LayoutInflater, ViewGroup, Bundle, View>() { 
     @Override 
     public View invoke(LayoutInflater arg1, ViewGroup arg2, Bundle arg3) { 
      View view = arg1.inflate(R.layout.layout_select_date_recyclerview,arg2,false); 
      return view; 
     } 
    }); 

    viewPagerView.setAdapter(selectDateAdapter); 

このソリューションは一般的ではありませんが、プロセスは非常に簡単です。

関連する問題