Я думаю, что мало вещей пошло не так с вашим кодированием.Старайтесь избегать жесткого фрагмента кода, например
android:name="com.me.cscomponents.fragFeed.FeedFragment"
На основании вашего вопроса я подготовил кое-что для вас.Я только что реализовал два нажатия кнопки, а не публикацию списка.Передал int (вы можете передать в соответствии с вашими потребностями.).Я пытался следовать нескольким лучшим практикам.Для простоты я использовал LinearLayout & RelativeLayout.
activity_test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".TestActivity">
<FrameLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
TestActivity.java
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class TestActivity extends AppCompatActivity implements FeedFragment.OnItemClickedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, FeedFragment.getInstance(), FeedFragment.TAG).commit();
}
@Override
public void onButtonClicked(int position) {
getSupportFragmentManager().beginTransaction().addToBackStack(null).replace(R.id.fragment_container, PlayerFragment.getInstance(position), PlayerFragment.TAG).commit();
}
@Override
public void onAttachFragment(Fragment fragment) {
if (fragment instanceof FeedFragment) {
FeedFragment feedFragment = (FeedFragment) fragment;
feedFragment.setOnButtonClickedListener(this);
}
}
}
фрагмент_фида.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Button
android:id="@+id/button_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Feed 1" />
<Button
android:id="@+id/button_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Feed 2"/>
</LinearLayout>
FeedFragment.java
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
public class FeedFragment extends Fragment {
public static final String TAG = FeedFragment.class.getSimpleName();
View view;
OnItemClickedListener callback;
Button buttonOne;
Button buttonTwo;
public static FeedFragment getInstance(){
FeedFragment fragment = new FeedFragment();
return fragment;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.feed_fragment, container, false);
buttonOne = view.findViewById(R.id.button_one);
buttonTwo = view.findViewById(R.id.button_two);
init();
return view;
}
private void init() {
buttonOne.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callback.onButtonClicked(1);
}
});
buttonTwo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
callback.onButtonClicked(2);
}
});
}
public void setOnButtonClickedListener(OnItemClickedListener callback) {
this.callback = callback;
}
public interface OnItemClickedListener {
public void onButtonClicked(int position);
}
}
frag_player.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/demo_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
PlayerFragment.java
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
public class PlayerFragment extends Fragment {
public static final String TAG = PlayerFragment.class.getSimpleName();
private static final String ARG_POSITION = "position";
private View view;
private TextView demoTextView;
private int position;
public static PlayerFragment getInstance(int position){
PlayerFragment fragment = new PlayerFragment();
Bundle args = new Bundle();
args.putInt(ARG_POSITION, position);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(getArguments() != null ){
position = getArguments().getInt(ARG_POSITION);
}
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_player, container, false);
demoTextView = view.findViewById(R.id.demo_text_view);
init();
return view;
}
private void init() {
demoTextView.setText("Player Fragment, clicked position "+ position);
}
}
Надеюсь, это поможет вам.Спасибо.