Dengan cara ini kita bisa memasukan fragment ke view apapun seperti Linear Layout, RelativeLayout, dan lainnya.
FragmentSaya.java
import android.support.v4.app.Fragment; public class FragmentSaya extends Fragment { @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_saya, container, false); processData(v); return v; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } private void processData(View v) { Bundle bundle = getArguments(); String data = bundle.getString("data"); } }
ActivitySaya.java
public class ActivitySaya extends AppCompatActivity { private void embedFragment() { fragmentSaya = new FragmentSaya(); Bundle data_saya = new Bundle(); data_saya.putString("data", data.toString()); fragmentSaya.setArguments(data_saya); FragmentManager fm = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fm.beginTransaction(); fragmentTransaction.add(R.id.linear_content, fragmentSaya); fragmentTransaction.commit(); } }
Tidak ada komentar:
Posting Komentar