If you want it on List Item Click
Fragment A:
public class FragmentA extends ListFragment {
OnItemSelectedListener mListener;
...
// Container Activity must implement this interface
public interface OnItemSelectedListener {
public void onItemSelected(int position);
}
...
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
mListener = (OnItemSelectedListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement OnItemSelectedListener");
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
mCallback.onItemSelected(position);
}
}
ContainerActivity:
public class ContainerActivity extends FragmentActivity
implements FragmentA.OnItemSelectedListener
{
//...
public void onItemSelected(int Position/*pass anything which u want*/)
{
SecondFragment second_fragment = (SecondFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentB);
if(second_fragment !=null)
{
second_fragment.UpdateUI(Position);
}
}
}
Second Fragment:
public class SecondFragment extends Fragment {
...
public void UpdateUI(Position)
{
}
}
Hope this helps. On click of a Button inside each listitem might be bit difficult, but try the same approach. May be you have to write the interface declaration and call in your custom adapter.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…