How to pass a cursor from a MainActivity using SearchView to a ListFragment - searchview

How could I make my ListFragment display the results in SearchView?
I have a MainActivity that acts as the container of a ListFragment and a SearchView. The scenario is once the user type something on the SearchView and press Enter, the ListFragment will display all the possible records that containing the word.
By the way, I am using a ContentProvider to handle my searching. It returns a Cursor object.
The ListFragment does not displays the desired output.
Please help.

Related

How to set the action of a NSButton in a binding scenario?

I have a button that is inside a view repeated inside a NSCollectionView. I can bind the title of the button to one of the properties in my model class but I want to wire the selector of the button to one of the selectors in my model class. Obviously, the button must send the message to the model object associated with the corresponding collection view item.
I managed to bind the target for the button but how to set the selector? I want to do that in Interface Builder if possible...
I figured it out. In the Ib there is a selector textbox bellow the path textbox where I bind the target. I don't know why I didn't see it. I spent nearly one hour trying to solve this issue.
How to add those blindings? I still can't find it.
I find it . It's Here.

How do I create a dynamic page based on a selection?

I am trying to dynamically fill a second panorama page based on what item was selected from the home application screen.
On the application's first start screen there is a listbox if items each with text. If a user taps on an item with text "foobar" a template page should load and the title of the template page should be set to "foobar" and this second panorama page should know that it's data should be related to "foobar".
Is there anyway to do this?
I currently have my MainPage navigate to a new page (DynamicPage.xaml). This navigation is triggered when a ListBox_SelectionChanged event occurs. I have the title text of the DynampicPage.xaml Binding to a TitleText variable that is located in MainPage.xaml.cs. However, when I do this the title of DynamicPage.xaml is ever only set to my initialization value for the titleText variable even though I am updating this variable right before I navigate to the page.
If anyone can provide some help I would be very grateful as I am just a beginner on the WP7 platform. Thanks!
The Binding you're using for the title is only going to update if the TitleText property is a dependency property or if your MainPage is implementing the INotifyPropertyChanged interface so your class can notify the UI when one of its properties changed.
http://windowsphonegeek.com/articles/All-about-Dependency-Properties-in-Silverlight-for-WP7
http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged(v=vs.95).aspx
But I think this is not the best way for you to achieve this. For now a much better way is to store your data somewhere in a static class, in the main page's constructor load these data into the listbox, and when the user selected an item, navigate the user to the second page like this:
NavigationService.Navigate(new Uri("/DynamicPage.xaml?Item=" + selectedItem.Id, UriKind.Relative));
When you navigate like this a new instance of DynamicPage is created, and in the OnNavigatedTo method you can access the navigation parameters and populate your page with the selected data. For example:
<controls:Panorama x:Name="MyPanorama" Title="TitleHere">...</controls:Panorama>
Item selectedItem = StaticData.GetItem(NavigationContext.QueryString["Item"]);
MyPanorama.Title = selectedItem.Name.ToUpper();
Description.Text = selectedItem.Description;
This way you can use secondary tiles and toast notifications to directly point to a specific content in your application.
If you're getting to understand the navigation you should definitely use the pattern called Model-View-ViewModel which is about to solve these problems mostly with bindings, but trust me, probably this is the easier way for now.

WP7 Listbox Binding: Changing image uri in does not reflect in listbox

I have a view with a list box, bound to am obvervable collection of DisplayItems, which has 'Label', 'DisplayValue' and 'IconUri' properties.
I have a View Model which exposes this observable collection. The List Box is correctly populated first time around.
I then have a button which takes action on the selected item. I need to indicate that action has been taken by changing the image.
I am changing the IconUri of the selected item, and can see the new value present when debugging, but the image doesn't change. I can also change the 'Label' and 'DisplayValue' properties and see the new values correctly there when debugging, but the list doesn't change.
My ViewModel implements INotifyPropertyChanged. My DisplayItem class implements INotifyPropertyChanged. I'm calling RaisePropertyChanged I'm sure in too many places rather than too few.
None of the changes are ever reflected on screen.
I'm using a DataItemTemplate for the generated rows. If I could access the image of the selected row I could change it manually, but I can't even do that.
Any help greatly appreciated. I could actually do with a example of a list box displaying items from a bound observable collection, where one property of the selected item is changed and that change is reflected in the list box.
Thanks in advance
A
You didn't implement INotifyPropertyChanged correctly, or you're using it wrong.

Can a view controller own a sheet?

I want to call a sheet from within a view controller (user clicks on a button and the sheet will be displayed). Can the sheet have a separate window controller (with outlets and actions) or does the view controller from which the sheet is called operate as the sheet's controller?
I'm trying to determine how to display a sheet from a separate Interface Builder (.xib) file than my view controller. The sheet will have a list based on a popup menu item, so I would like to put that "logic" in a separate controller. I tried using a NSWindowController, but that didn't work.
A stock NSViewController controls a view; nothing more. You can make a custom subclass that owns the sheet, or you can make it own a window controller which owns the sheet. The choice is yours.
Tried using a NSWindowController, but that didn't work.
You should ask another question about that.

Call a function when a user presses enter in an NSSearchField?

I am surprised that I can't find the answer to this simple task. I just want the user to type in text, press enter, and have the application know what s/he typed. How would I do this?
NSSearchField supports the action target mechanism, so simply hook it to a target/action. For instance, suppose you have the following action declared in your application delegate:
- (IBAction)searchAnswer:(id)sender;
In Interface Builder, ctrl-drag your search field to the application delegate object and choose the searchAnswer: action. In its implementation, use -stringValue to obtain the text typed by the user into the search field, e.g.
- (IBAction)searchAnswer:(id)sender {
NSLog(#"search answer: %#", [searchField stringValue]);
}
Note that by default the search field sends the action when the user pauses/stops typing, too. If you want it to send the action only when the user types Enter, choose the Sends Whole Search String checkbox in the search field attributes inspector window.

Resources