Android NavigationDrawerFragment: Control whether the child fragment or parent activity's onCreateOptionsMenu gets calle
By : user2445082
Date : March 29 2020, 07:55 AM
this one helps. So like I mentioned in the title, I have a setup with a NavigationDrawerFragment and another fragment in a containing activity. , In your Activity let have this: code :
@Override
public boolean onCreateOptionsMenu(MenuInflater inflater, Menu menu){
boolean onlyFragments = !mDrawerLayout.isOpened(GravityCompat.START);
Fragment visibleFragment = getSupportFragmentManager().findFragmentById(R.id.content_layout);
visibleFragment.setHasOptionsMenu(onlyFragments);
if(onlyFragments){
return super.onCreateOptionsMenu(inflater,menu);
}else{
//here only activity inflates menu
inflater.inflate(R.menu.activity_menu, menu);
return true;
}
}
|
How to send ArrayList from Activity to NavigationDrawerFragment?
By : Lucas Novelo
Date : March 29 2020, 07:55 AM
will help you I need to send ArrayList from Activity to NavigationDrawerFragment. I use parcelable, but in fragment getArgument is null( , Your problem is here: code :
mNavigationDrawerFragment = new NavigationDrawerFragment();
mNavigationDrawerFragment.setArguments(NavItems);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mNavigationDrawerFragment = (NavigationDrawerFragment)
getFragmentManager().findFragmentById(R.id.navigation_drawer);
mNavigationDrawerFragment.setArguments(NavItems);
|
How to send data from Child Activity to Parent Activity in android?
By : user3483843
Date : March 29 2020, 07:55 AM
With these it helps In my manifest.xml, i'm used android:parentActivityName to set up parent Activity. Here my code: , In your Activity B class write: code :
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// Respond to the action bar's Up/Home button
case android.R.id.home:
Intent intent= new Intent();
intent.putExtra("param", "value");
setResult(RESULT_OK, intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == 2404) {
if(data != null) {
String value = data.getStringExtra("param");
}
}
}
Intent intent = new Intent(A.this.getApplicationContext(), B.class);
startActivityForResult(intent, 2404);
|
send data from one activity to another activity / fragment via Intents through Custom Adapter for List items in android
By : Alice
Date : March 29 2020, 07:55 AM
help you fix your problem I am a beginner android programmer and i am making an Restaurant App that contains spinner of Franchise cities in One Activity and if the user selects one of the cities from the Spinner and click the button, it should display the list of restaurants for selected city in another activity / fragment. How to achieve this through Custom Adapter?? , The answer includes two parts : - code :
ListView yourListView = (ListView) findViewById(R.id.itemListView);
ListAdapter customAdapter = new ListAdapter(this, R.layout.itemlistrow, <<restaurantList>>);
yourListView .setAdapter(customAdapter);
public class ListAdapter extends ArrayAdapter<Item> {
public ListAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public ListAdapter(Context context, int resource, List<Item> items) {
super(context, resource, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi;
vi = LayoutInflater.from(getContext());
v = vi.inflate(R.layout.itemlistrow, null);
}
Item p = getItem(position);
if (p != null) {
TextView tt1 = (TextView) v.findViewById(R.id.id);
TextView tt2 = (TextView) v.findViewById(R.id.categoryId);
TextView tt3 = (TextView) v.findViewById(R.id.description);
if (tt1 != null) {
tt1.setText(p.getId());
}
if (tt2 != null) {
tt2.setText(p.getCategory().getId());
}
if (tt3 != null) {
tt3.setText(p.getDescription());
}
}
return v;
}
|
Is there a consistent way to send data to an Android activity, opening the activity if it is not already open?
By : Alex Jackson
Date : March 29 2020, 07:55 AM
I wish this help you But this doesn't seem to work if activity is already open because you can't access to the most recent intent
|