Open item with context menu action - java

I'm new to android and java and I'm trying to work on an app.
The reason I'm seeking for help is that I can't figure out how to replicate the action of single tapping on an item of a list (action that opens the item) in a context menu (which appears with a long tap on the item). I can't associate the field I created ("Modify item") to actually open the selected item. I can't post any part of the code and I'm sorry about that, hope you might understand and help anyways.
Thanks

Related

Android Espresso - Closing the SearchView

I'm working on Espresso tests for Android and for one of my actions I want to search a list using a SearchView, select an item and then navigate back to the previous screen (by closing the searchview and then pressing the up button).
I've tried some things to access the up/collapse button of the SearchView to close it (that don't work):
onView(withContentDescription(R.string.abc_action_bar_up_description))
onView(withId(R.id.search_close_btn))
onView(withId(R.id.home))
onView(withId(R.id.homeAsUp))
onView(withId(R.id.collapseActionView))
Espresso.pressBack() (to just navigate back)
I'm hoping someone might know some way to access and close this button, because I have no idea.
Thanks in advance.
Apparantly I had to press the back button twice to navigate out of it, so if anyone would like to know, you need to use Espresso.pressBack(); twice to get out of the search menu.
The correct id is R.id.search_close_btn
onView(withId(R.id.search_close_btn)).perform(click())
I was with the same problem of accessing this up/collapse button and by reading the hierarchy of components I found out that this button has the content description of 'Collapse'. So using the following solved the problem for me:
onView(withContentDescription(androidx.appcompat.R.string.abc_toolbar_collapse_description)).perform(click())

Programmatically Perform Child View Click in ExpandableListView

I have an ExpandableListView implementation in my application and I am writing unit tests for it. I'm wondering how I can programmatically perform a click on the child view of an expandable header?
This is NOT a question about how to attach onChildClickListener() to the view. I've found many questions regarding that topic, but I already have that implemented and need to test the functionality of that code when the child view is clicked. I know that I can use the performClick() method to click on the header view to expand/collapse the contents, but I need to perform a click on the sublist of a header.
You can try with:
listView.setSelection(position);
but you have to consider this:
If in touch mode, the item will not be selected but it will still be
positioned appropriately. If the specified selection position is less
than 0, then the item at position 0 will be selected.
For more information you can visit the doc page.
I hope it helps.
Edit
As #RyanM appointed, setSelection just change the selection, but it doesn't perform the "click" action. You can perform the action through the function:
listView.performItemClick(goalListView, itemPosition, itemId);
You can find this function in the class AdapterView.
Sorry for the previous mistake to your answer.

How to display popup menu in Eclipse E4 MPart

In Eclipse E4, detached view option is not available but this is very important requirement for our project, So i want to add popup menu in MPart to provide the functionality.
Please guide me how can i add popup menu in MPart. I tried adding it in application model but it seems i am doing something wrong.
Thanks in Advance!
Add a popup menu and handled menu item to the MPart in your .e4xmi
Make sure you get the id's correct. The handler will be the code you want to run
see here for an example:
http://www.vogella.com/tutorials/EclipseRCP/article.html#menuadvanced_popup

PreferenceActivity, how to make a Preference item that will navigate back through menus?

My overriding question is this: In Android PreferenceActivity, how can I write an OnClickListener which will have the same functionality as pressing the Android back button as I navigate through PreferenceScreen defined menus? That is to say, I would like users of my App to explicity see a menu choice "Back" which will bring them to the previous menu, or bring them out of the menu activity to their previous activity if they are at the root of this particular PreferenceActivity session.
The android developer documents tell us
Note that this XML resource contains a preference screen holding another fragment, the Prefs1FragmentInner implemented here. This allows the user to traverse down a hierarchy of preferences; pressing back will pop each fragment off the stack to return to the previous preferences.
And they are correct about that. I navigate happily through my menus by clicking on PreferenceScreen items to get to that screen, and using the Android back button to go Back up a level. But I'm not sure a casual user really understands the "Back" button, I know I didn't until I read about it in Developer docs. SO I would would like them to have an explicit Preference defined menu choice whos OnClickListener duplicates the function of the Android back button.
So I tried to put in a Preference in my menu that would go back. Having determined that a not Overriden onBackPressed in a my subclass of PreferenceActivity just referred back to Activity.onBackPressed() which merely calls finish(), I tried this OnClickListener:
private OnPreferenceClickListener clickFinishesSuccessfully = new OnPreferenceClickListener() {
#Override
public boolean onPreferenceClick(Preference preference) {
finish();
return true;
}
};
As it turns out, this did NOT do the same thing as pressing the back button! Pressing this button always took me out of the PreferenceActivity entirely, back to the Activity from which I had called my PreferenceActivity. Specifically, it did NOT navigate back through my menus no matter how deep I was when I clicked it.
I am guessing here: When I have gotten to a submenu by clicking an onscreen preference which is really a PreferenceScreen, I am no longer in my own PreferenceActivity. I must be in some other Activity?
So my functional question: what can I put in my OnClickListener of my "Back" Preference to get the same function as the Android Back button navigating through my menus?
I think the casual user should know about the back button. The button is used everywhere so it might be a problem getting used in the first day but after that it's natural. Without being used to the "back" button I can hardly imagine doing the everyday tasks.
The preference you want to add just duplicates functionality and doesn't provide a consistent way with the rest of the system. If Google was considering back being an uncommon thing for casual users would have added that option in phone's Settings which is also a PreferenceActivity.

Adding menu entries to Blackberry menu list

Blackberry applications have a "menu" list coming up when you hit the Blackberry menu button. (When you inherit from "MainScreen".) But in my application there is only one entry, "Close".
How do I add entries to this menu?
(This is not a dupe of this question, which is about replacing the standard menu with an entirely custom menu.)
create a menu item using the net.rim.device.api.ui.MenuItem. You can add it to a MainScreen with the addMenuItem(MenuItem item) function.
EDIT
sample code
MenuItem mi=new MenuItem("mymenuitem",1,1);
addMenuItem(mi);

Categories