我想刪除一個片段,並顯示一個烤麪包,當我點擊一個textView。我的代碼顯示吐司,但不刪除片段。刪除不工作的片段
我的方法:
public void hide(View view) {
My_frag myFrag= new My_frag();
FragmentTransaction transaction = getSupportFragmentManager()
.beginTransaction();
transaction.remove(myFrag);
transaction.commit();
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_LONG)
.show();
}
My_frag類:
public class My_frag extends android.support.v4.app.Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.my_frag_layout, container, false);
}
}
是的,我加在片段之前發生的按鈕點擊。當我點擊進入editText視圖時,我想讓片段消失。我會嘗試你的建議並留下評論。謝謝 – EGHDK 2012-07-29 20:43:40
它的工作。我只是把'My_frag myFrag = new My_frag();我的應用程序的頂部有' ',並且在'show()'和'hide()'方法中刪除了這一行。 – EGHDK 2012-07-29 20:47:42