フラグメント1に進むには、フラグメント2と次のフラグメント1を取得する必要があります。 私のコードに何がありますか?メインアクティビティーにフラグメントが表示されないアクティビティーのフラグメントコンテンツはツールバーをクリックすると表示されます
は、これは私のフラグメント
public class TodaysmemeFragement extends Fragment {
private RecyclerView recyclerView;
private DatabaseReference databaseReference;
private FloatingActionButton sharebutton;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_todaysmeme,container,false);
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Meme,MemeViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Meme, MemeViewHolder>(
Meme.class,
R.layout.meme_row,
MemeViewHolder.class,
databaseReference
) {
@Override
protected void populateViewHolder(MemeViewHolder viewHolder, final Meme model, final int position) {
viewHolder.setTag(model.getTag());
viewHolder.setDesc(model.getDesc());
viewHolder.setImage(getActivity(),model.getImage());
final String imageurl = model.getImage();
View v = viewHolder.getmViews();
FloatingActionButton f = (FloatingActionButton) v.findViewById(R.id.sharebutton);
f.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
URL url = null;
Bitmap image = null;
try {
url = new URL(imageurl);
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
image = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_TEXT, model.getDesc());
Uri screenshotUri = null;
String path = null;
try {
path = MediaStore.Images.Media.insertImage(getActivity().getContentResolver(), image, "", null);
screenshotUri = Uri.parse(path);
} catch (Exception e) {
Log.d(e.getLocalizedMessage(),"dfsf");
}
intent.putExtra(Intent.EXTRA_STREAM, screenshotUri);
intent.setType("image/*");
startActivity(Intent.createChooser(intent, "Share image via..."));
}
});
}
};
recyclerView.setAdapter(firebaseRecyclerAdapter);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
getActivity().setTitle("Today's Meme");
sharebutton = (FloatingActionButton) view.findViewById(R.id.sharebutton);
databaseReference = FirebaseDatabase.getInstance().getReference("Today");
recyclerView = (RecyclerView)view.findViewById(R.id.meme_list);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}
public static class MemeViewHolder extends RecyclerView.ViewHolder{
View mView;
public MemeViewHolder(View itemView)
{
super(itemView);
mView = itemView;
}
public void setTag(String tag)
{
TextView post_tag = (TextView)mView.findViewById(R.id.post_tag);
post_tag.setText(tag);
}
public void setDesc(String desc)
{
TextView post_desc = (TextView)mView.findViewById(R.id.post_desc);
post_desc.setText(desc);
}
public void setImage(Context context,String image) {
ImageView imageView = (ImageView) mView.findViewById(R.id.post_image);
Picasso.with(context).load(image).into(imageView);
}
public View getmViews()
{
return this.mView;
}
}
}
ですこれは、XMLには問題はありません私のMainActivity
<android>
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
DatabaseReference databaseReference;
FirebaseAuth firebaseAuth;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
Fragment fragment;
fragment = new TodaysmemeFragement();
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction()
.replace(R.id.content_main, fragment)
.commit();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
firebaseAuth = FirebaseAuth.getInstance();
if(firebaseAuth.getCurrentUser() == null)
{
finish();
startActivity(new Intent(getApplicationContext(),LoginSignupActivity.class));
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
です。しかし、断片の中の何かが置き換えられます。
android.R.id.contentを追加すると、通知トレイが無効になります。 – Malavan
動作しませんでした。 TodaysmemeFragmentのライフサイクルをチェックできますか?私はそれ自身の問題だと思う。 – Malavan
あなたの努力Shobhitに感謝します。最後に問題の原因を突き止める。 "recyclerView.setHasFixedSize(true)"を削除すると、問題が解決します – Malavan