[Q] How to dismiss contextual action bar programmatically - Java for Android App Development

I am using contextual action bar for lisview check box.I want to dismiss it programmatically to ensure that it is hidden if no check box is selected. [/code]private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
// called when the action mode is created; startActionMode() was called
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
// assumes that you have "contexual.xml" menu resources
inflater.inflate(R.menu.contextual, menu);
return true;
}
// the following method is called each time
// the action mode is shown. Always called after
// onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false; // Return false if nothing is done
}
// called when the user selects a contextual menu item
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.cut:
getActivity().finish();
// the Action was executed, close the CAB
return true;
default :
return false;
}
}
// called when the user exits the action mode
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
checkedindex.clear();
loadlist(new File(prog.getText().toString()));
checkedindex.clear();
selection=false;
}
};
[/Code]
I am using it like this
Code:
mActionMode = getActivity().startActionMode(mActionModeCallback);
Where mActionMode is object(Universal)
I have tried mActionMode=null; or mActionMode.finish() etc.
Sent from my GT-S5570 using XDA Premium 4 mobile app

Related

how do i create a donate menu

I am having trouble creating a donate menu button but I am having trouble
I tried doing it as a webview but my application is the use of the listview
Code:
private static final int MENU_DONATE = 0;
Code:
/* Creates the menu items */
public boolean onCreateOptionsMenu(Menu menu)
{
menu.add(0, MENU_DONATE, 0, "Home");
return true;
}
/* Handles item selections */
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case MENU_DONATE:
myweb.loadUrl("https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A2L64XS44ZQ9S");
return true;
}
return true;
}
but it is not working and giving me errors what do i need to fix this and get it to work correctly

[Q] about page switch

I have the menu with 2 options, settings and cancel. The setting will direct to the setting page. Here is the code I wrote so far.
Code:
static final private int SETTINGS = Menu.FIRST;
static final private int CANCEL = Menu.FIRST + 1;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
// Create and add new menu items.
MenuItem itemSet = menu.add(0, SETTINGS, Menu.NONE, "Settings");
MenuItem itemCan = menu.add(0, CANCEL, Menu.NONE, "Cancel");
// Assign icons
itemSet.setIcon(android.R.drawable.ic_menu_preferences);
itemCan.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
super.onOptionsItemSelected(item);
if (item.getItemId()== SETTINGS){
Intent settingIntent = new Intent(this, setting.class);
startActivityForResult(settingIntent, 0);
}
else if (item.getItemId()== CANCEL){
//do nothing
}
return true;
}
the setting class is
Code:
public class setting extends Activity{
private Button browseButton;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.setup);
browseButton = (Button) findViewById(R.id.Btn_Browse);
browseButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
Intent fcIntent = new Intent(v.getContext(), filechooser.class);
startActivityForResult(fcIntent, 0);
}
});
}
}
However, I got an error which is about the program stopped unexpectedly....
could anyone advices me where my program get wrong?
Thank you.

[Q] Using Split Action in android

Hi!
My self Raj, i have a problem when using the split action in my application.
i am doing an E-Menu for an restaurant. i list out all available category in major listview if the user click on the item of major list it should display all available minor items of its in behind of the Major listview.
I found one solution in Google it is possible by using split action.
Can anyone guide me / give some sample i may know about it..,
I am waiting for your guide.,
Have A Happy Day..,
Thanks to all..,
Simply add the following line to your <activity> or <application> tag in your AndroidManifest :
Code:
uiOptions="splitActionBarWhenNarrow"
EDIT : As a side note, it seems you want the split actionbar to be displayed only after the user clicked something, in that use case, the Contextual ActionBar seems more suited.
To use it, simply define your actionbar items in a menu.xml just like the normal actionbar, then in your java code use something like :
Code:
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
return false;
}
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item1:
//do something
mode.finish();
return true;
case R.id.menu_item2:
// do something else
mode.finish();
return true;
case R.id.menu_item3:
// etc....
mode.finish();
return true;
default:
return false;
}
}
@Override
public void onDestroyActionMode(ActionMode mode) {
mActionMode = null;
}
And in the onClickListener() of the component that triggers the contextual ActionBar, call it like that :
Code:
if (mActionMode != null)
// Do nothing
else
mActionMode = startActionMode(mActionModeCallback);
You might want to use the ActionBarSherlock Library in order to keep compatibility with gingerbread/froyo

Share Action Provider is unresponsive

i want to share a layout as an image. code listed below is working fine for the save action button but not for share action button. share action button remains unresponsive. i am unable to figure it out what is wrong.
Code:
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.eid_card_final, menu);
MenuItem item = menu.findItem(R.id.action_share);
myshare = (ShareActionProvider)item.getActionProvider();
String sharestate = Environment.getExternalStorageState();
RelativeLayout rlShareLayout = (RelativeLayout)findViewById(R.id.relativeLayout);
Bitmap sharebitmap = Bitmap.createBitmap(rlShareLayout.getWidth(), rlShareLayout.getHeight(), Bitmap.Config.ARGB_8888);
Canvas sharecanvas = new Canvas(sharebitmap);
rlShareLayout.draw(sharecanvas);
try{
if (Environment.MEDIA_MOUNTED.equals(sharestate)) {
Random sharerand = new Random();
int sharerandnum = sharerand.nextInt(1000);
String sharefilename = sharerandnum + ".jpeg";
sharef = new File(getExternalFilesDir(null),sharefilename);
FileOutputStream shareout = new FileOutputStream(sharef);
boolean success = sharebitmap.compress(CompressFormat.PNG, 100, shareout);
}
} catch (Exception e) {
e.printStackTrace();
}
Intent shareintent = new Intent(Intent.ACTION_SEND);
shareintent.setType("image/*");
Uri shareuri = Uri.fromFile(sharef);
shareintent.putExtra(Intent.EXTRA_STREAM, shareuri.toString());
shareintent.setData(shareuri);
myshare.setShareIntent(shareintent);
return true;
}

PreferenceFragment and Tabs

Hi,
currently I am developing a App.
I use the NavigationDrawer to set up a Menu (with the "Burger-Button") on the left side.
Wenn I choose a menu item, for example a PreferenceFragment i displayed.
My problem: I want to display a Tab-Layout with a PreferenceFragment in each Tab.
But I don´t know how...
In my MainActitivty-Class (AppCompatActivity) I change the content of my App (after the user clicked on a menu item) like this:
Code:
@Override
public boolean onNavigationItemSelected(MenuItem item) {
FragmentTransaction fragmentTransaction = this.getFragmentManager().beginTransaction();
int id = item.getItemId();
// Globale Eistellungen
if (id == R.id.nav_main_settings) {
fragmentTransaction.replace(R.id.containerView, new MainPreferenceMenu());
fragmentTransaction.commit();
}
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
Whereby "MainPreferenceMenu" is a PreferenceFragment.
I tried it with this tutorial: https://guides.codepath.com/android/google-play-style-tabs-using-tablayout
First Problem: I can´t set my PreferenceFragment here:
Code:
@Override
public Fragment getItem(int position) {
return PageFragment.newInstance(position + 1);
}
Because "PreferenceFragment" is the wring Class.
Also I don´t know how to set the "ViewPager" like in the Tutorial (MainActivity).
Can anybody help me?
I hope my Problem is clear.
Using view pager for tabs is the best option as it behaves as per material guide lines.

Categories

Resources