0

私は現在、データをタブ/フラグメント間で移動する必要があるプロジェクトで作業しています。ユーザーがlistViewアイテムをクリックして、別のタブに移動する同じタブに留まる私はそれをどのように達成できるのか分かりますか?誰かが私の質問を解決するのを助けることができる?ありがとうございました!Android Studio - データがタブ/フラグメント内で移動する

答えて

0

あなたはセットで、タブの間でデータをtrasnferと引数を取得することができ、 は、ここでデータを渡すために、この

1)使用するインターフェイス -useインタフェースを行うための3つの方法があります例

FragmentTwo fragmentTwo = new FragmentTwo(); 

Bundle bundle = new Bundle(); 
bundle.putString("key1", "data1"); 
bundle.putString("key2", "data2"); 
bundle.putString("key3", "data3"); 
fragmentTwo.setArguments(bundle); 

FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction(); 
fragmentTransaction.replace(R.id.main_container, fragmentTwo); 
fragmentTransaction.commit(); 
0

ですオブジェクト。網状ソリューション

Read more

public interface onDataCHange{ 
    public void updateData(String data); 
} 

2)使っ活動クラス - ストアモデル活動クラスのオブジェクトと設定し、アクティビティのインスタンスを使用して取得します。迅速かつ汚いソリューション

Read more

//Get 
    Object dataModel = (ContainerActivity) getActivity()).getData(); 

    //Set 
    ((ContainerActivity) getActivity()).setData(dataModel); 

3)クリーンアーキテクチャ - センターリポジトリホールドモデルオブジェクト。 Singleton Centerリポジトリオブジェクトを介して更新モデルを表示します。アプリケーション全体でのデータフローの単一コピー。

Read more

@Singleton 
public class UserDataRepository implements UserRepository { 

    private final UserDataStoreFactory userDataStoreFactory; 
    private final UserEntityDataMapper userEntityDataMapper; 

    /** 
    * Constructs a {@link UserRepository}. 
    * 
    * @param dataStoreFactory A factory to construct different data source implementations. 
    * @param userEntityDataMapper {@link UserEntityDataMapper}. 
    */ 
    @Inject 
    UserDataRepository(UserDataStoreFactory dataStoreFactory, 
     UserEntityDataMapper userEntityDataMapper) { 
    this.userDataStoreFactory = dataStoreFactory; 
    this.userEntityDataMapper = userEntityDataMapper; 
    } 

    @Override public Observable<List<User>> users() { 
    //we always get all users from the cloud 
    final UserDataStore userDataStore = this.userDataStoreFactory.createCloudDataStore(); 
    return userDataStore.userEntityList().map(this.userEntityDataMapper::transform); 
    } 

    @Override public Observable<User> user(int userId) { 
    final UserDataStore userDataStore = this.userDataStoreFactory.create(userId); 
    return userDataStore.userEntityDetails(userId).map(this.userEntityDataMapper::transform); 
    } 
} 
関連する問題