0

フラグメントを含むアプリがあります。それは正常に動作します。

フラグメントの 1 つにボタンがあり、押されたときにビューを変更したいと考えています。

public class BikeRecap extends Fragment {

public static Activity activity;
public static Context context;


/** Called when the activity is first created. */


public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    activity = getActivity();
    context = activity.getApplicationContext();

    View view = inflater.inflate(R.layout.bike_recap, container, false);        

    ImageButton details = (ImageButton) item.findViewById(R.id.details);


    details.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              OpenNewView();
          }
    });

    return view;
}

OpenNewView() はビューを変更する必要があるため、ユーザーは同じタブにいますが、コンテンツは異なります

出来ますか?

4

2 に答える 2

1

フラグメント内にフラグメントを含めることはできません。

このコードを試してください:

FragmentManager fragmentManager2 = getFragmentManager();
FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
DetailFragment fragment2 = new DetailFragment();
fragmentTransaction2.addToBackStack("abc");
fragmentTransaction2.hide(BikeRecap.this);
fragmentTransaction2.add(android.R.id.content, fragment2);
fragmentTransaction2.commit();
于 2013-01-17T12:26:31.960 に答える
0

やろうとしていることは、かなり簡単にできると思います。OpenNewView がフラグメントではなくアクティビティによって実装されている場合:

getActivity().openNewView(...)

... その後、Activity は、標準のトランザクション メカニズムを使用して、現在のフラグメントを新しいフラグメントに簡単に置き換えることができます。

G. ブレイク メイケ マラカナ

Android 2ed のプログラミングが店頭に並びました: http://bit.ly/programmingandroid

于 2013-01-17T18:52:03.840 に答える