notifyDatasetchanged not working for ArrayAdapter - arraylist

I am trying to implement 2 AutoCompleteTextView. First one holds the value, on click of one of them will populate the data in second AutoCompleteTextView, all works and data gets loaded correctly however when I try to call notifyDataSetChanged on the second adapter which populates the second field that does not get changed.
I also wrote that piece of code inside a Handler too, however that does not seems to work either.
branchAdapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1,branchNames);
et7.setAdapter(branchAdapter);//et7 is the AutoCompleteTextView //branchname is the ArrayList
in some method I clean up the ArrayList and add the new data into it and then call notifyDataSetChanged like below
Handler handler = new Handler(Looper.getMainLooper());
handler.post(new Runnable() {
#Override
public void run() {
branchAdapter.notifyDataSetChanged();
}
});
Which is not updating the list. What should be the correct way here to update data?

#Saty, I guess i am a little late to the party. I am answering, keeping in mind that, it may help somebody in future.
Cleanup the adapter as well using branchAdapter.clear() method. Then add new items to the adapter using branchAdapter.addAll(String... items) method. Now, call branchAdapter.notifyDataSetChanged() method. This will work.

Try resetting listview instead.
ListView lv = (ListView)findViewById(R.id.lv);
ArrayAdapter adapter = new ArrayAdapter(/*with all parameters*/);
lv.setAdapter(adapter);

Related

Invoking Method of Presenter on Activation

I'm using Smart Client Software Factory 2008. In the module controller, I have code that creates a new child controller only if it hasn't been created, by doing something like the following:
Dim key = "Item-" + item.ID.ToString()
Dim childWorkItem = Me.WorkItem.WorkItems.Get(Of ControlledWorkItem(Of ItemWorkItemController))(key)
If childWorkItem Is Nothing Then
childWorkItem = Me.WorkItem.WorkItems.AddNew(Of ControlledWorkItem(Of ItemWorkItemController))(key)
Else
childWorkItem.Activate()
End If
Multiple items reuse the same key, so when that action is triggered, it shows the tab instead of creating a new instance of it. This works great.
However, there is one drawback. Once activated, I need to run a check within that item's presenter. So I need to call a method on the presenter. Is there a way to invoka a method on the presenter, or is there an event that runs on the view when the work item is activated? I'm not sure how to make that happen?
Thanks.
If you are using a Smart Part as your View you should be able to accomplish this using the IWorkspace.SmartPartActivated event.
This is how I have it setup in my project. I apologize, my code is all in C# but you should be able to apply it in VB relatively easily.
The WorkItemController class has the Activate method setup like this
ISmartPartView _smartPartView
public void Activate()
{
IWorkspace contentWorkspace = this.WorkItem.Workspaces[WorkspaceNames.ShellContentWorkspace];
contentWorkspace.Activate(_smartPartView);
WorkItem.Activate();
}
In the ISmartPartView Presenter class you should be able to create a handler for the SmartPartActivated event like this:
IWorkspace contentWorkspace = this.WorkItem.Workspaces[WorkspaceNames.ShellContentWorkspace];
contentWorkspace.SmartPartActivated += workSpaceSmartPart_ActivatedHandler;
In the workSpaceSmartPart_ActivatedHandler event handler, you can check the SmartPart being activated and if its your ISmartPartView class you can run the desired code.

How to create new instance of a view/viewmodel when navigation occurs with Prism

I am trying to control when a new view is created and when an existing view is shown.
This is a very similar scenario as outlined in the "Navigating to Existing Views" section in the Prism documentation, but I can't get it to work fully:
http://msdn.microsoft.com/en-us/library/gg430861(v=pandp.40).aspx
I am finding I can create the view/view model to begin with ok, but I am then unable to create a new instance of it. I.e. I want more than one instance to exist at once.
Here's an example of the view model:
[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class DataEntryPageViewModel : INavigationAware, IRegionMemberLifetime
{
private Guid id;
[ImportingConstructor]
public DataEntryPageViewModel()
{
id = Guid.NewGuid();
}
public bool IsNavigationTarget(NavigationContext navigationContext)
{
// In actual fact there would be more logic here to determine
// whether this should be shown to the user
return false;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
}
public bool KeepAlive
{
// For the purposes of this example we don't want the view or the viewModel
// to be disposed of.
get { return true; }
}
}
I am navigating to this as follows:
m_RegionManager.RequestNavigate(
"MainRegion",
new Uri("/DataEntryPageView", UriKind.Relative));
So the first time I call the above the view is shown.
The next time I call RequestNavigate the IsNavigationTarget is hit and it returns false. What I then want it to do is to create a new instance but that doesn't happen. I know it's not happening because the constructor does not get hit and the UI does not update to show the new instance of the view.
Any ideas how I can make it create a new instance?
Many thanks,
Paul
Edit
I have noticed that the second time I call RequestNavigate (to request another instance of the same view) the callback reports an error "View already exists in region." It therefore seems that I can have multiple instances of different views in a region, but not multiple instances of the same view. My understand of this isn't great though so I could be wrong.
Why are you not creating the view when you want a new one to be created? It looks to me like you are using MEF.
Use the container to resolve a new instance of your view
Add the new instance of the view to the MainRegion
Then call Navigate and handle the appropriate logic in IsNavigationTarget
You should use the [Export] attribute in your view with a contract name: [Export("DataEntryPageView")].
I have now been able to get this to work, it was because I didn't have
[PartCreationPolicy(CreationPolicy.NonShared)]
on the class declaration of the view. I had it on the ViewModel.
So this is now resulting in the behaviour I expected.
Thanks though to Zabavsky and Alan for your suggestions.

I can't load my SmartGWT Datasource

I'm modifying an example of the built-in-ds. The way this example works is that you need to select a datasource, and then a table gets filled with data from there. The idea is to show how the same component can adapt to multiple data sources. I've managed to run the example and it works, but I'm trying to modify it so you skip the first step - there's only one data source that gets loaded "into" the table. What puzzles me is that this should be trivial but for some reason it's not. I'll paste just the different parts of code, this one works:
// we create a list of datasources
ListGrid grid = new ListGrid();
grid.setLeft(20);
grid.setTop(75);
grid.setWidth(130);
grid.setLeaveScrollbarGap(false);
grid.setShowSortArrow(SortArrow.NONE);
grid.setCanSort(false);
grid.setFields(new ListGridField("dsTitle", "Select a DataSource"));
// I'm just loading the one I need
grid.setData(new ListGridRecord[] { new DSRecord("predmeti", "predmeti")});
grid.setSelectionType(SelectionStyle.SINGLE);
grid.addRecordClickHandler(new RecordClickHandler() {
public void onRecordClick(RecordClickEvent event) {
DSRecord record = (DSRecord) event.getRecord();
bindComponents(record.getDsName());
}
});
grid.draw();
and this is the bindComponents method:
private void bindComponents(String dsName) {
DataSource ds = DataSource.get(dsName);
boundList.setDataSource(ds);
boundViewer.setDataSource(ds);
boundForm.setDataSource(ds);
boundList.fetchData();
newBtn.enable();
saveBtn.disable();
}
and this works as it should. Now, since I only have one data source, I can skip the grid and just make the call to bindComponents:
bindComponents();
And bindComponents looks like this:
private void bindComponents() {
DataSource ds = DataSource.get("predmeti");
boundList.setDataSource(ds);
boundViewer.setDataSource(ds);
boundForm.setDataSource(ds);
boundList.fetchData();
newBtn.enable();
saveBtn.disable();
}
I can't see why the second doesn't work, it breaks on boundList.setDataSource(ds);. I inspected it in Debug mode, an object is returned and it looks "the same" in both cases but for some reason it doesn't work in the second example, so I'm guessing I'm instancing the data source too early or, somehow, just plain wrong :)
Everything was fine with the datasources, the problem is trivial and I must have just been tired - the boundList object at the time of this call boundList.setDataSource(ds); was not yet instantiated. I kept getting Null pointer exception, but I thought there was something wrong with the DataSource.

Adding content to silver light controls from database using wcf ria services

I am trying to retrieve strings from the database and add it as content to the controls on my page before it loads(somewhat like a custom localization). I retrieve my strings from the database uing ria services as follows:
**
Web.DomainService1 context = new Web.DomainService1();
LoadOperation<Web.LocalizationTab>LoadOp=context.Load(context.GetLocalizationTabsQuery(currentCulture, moduleName));
Dictionary<string, string> localizationDictonary = new Dictionary<string, string>();
List<Web.LocalizationTab> localList = new List<Web.LocalizationTab>();
LoadOp.Completed += (s, e) =>
{
localList = LoadOp.Entities.ToList<Web.LocalizationTab>();
//System.Windows.MessageBox.Show(localList.Count.ToString());
foreach (Web.LocalizationTab item in localList)
{
// var control = this.FindName(item.Control_ID.ToString());
if (!localizationDictonary.ContainsKey(item.Control_ID))
{
localizationDictonary.Add(item.Control_ID, item.Control_Text);
}
}
};**
This piece of code is in a separate class called utilities.cs.
now in my Mainpage.xaml.cs i need to get this dictionary with values and then set the controls with the strings from the dictionary.
my problem is that when i do the following in the constructor of Mainpage.xaml.cs:
utilities.getDict(ModuleName);
button1.Content = localizationDictonary["button1"].ToString();
i get an exception as the dictionary doesnt contain values at that point of time.. The load completed event of getting data from the database gets fired only after my constructor is exited. now how do i go about setting my controls automatically in this particular scenario??
Try loading your dictionary in the Silverlight Application class StartUp event. This should ensure that your Dictionary is loaded (and could be placed in the Application Resources for retrieval elsewhere in your application).
You'll need to wait for the GetLocalizationTabsQuery to complete before instantiating your MainPage. In your App.xaml.cs file, you can start the query, add a query completed handler, and only create the MainPage when the query completed handler gets called.

cellBrowser placed in composite - do I have to attach directly to the rootpanel (or rootlayoutpanel)

when using a cellbrowser and adding that widget to a flowpanel (to be placed wherever, downstream), for some reason the end result is dead (a blank screen)...vs if I add directly to the rootpanel (or layout panel)
Also had the same problem. I had to use a <g:HTMLPanel> as the parent of the CellBrowser (as seen in the GWT Showcase).
Do you have some sample code that will reproduce this?
below is the code for the composite...essentially, what I'd like to do is in another class, attached this composite to a flowpanel and do whatever with it...but, the reality is, I have to attach is directly to the RootPanel (or RootLayoutPanel)...any other abstraction causes it to bail
for example
FlowPanel fp = new FlowPanel();
V2_M76Rolodex v = new V2_M76Rolodex();
fp.add(v); // not going to work
RootPanel.get.add(v) works
public class V2_M76Rolodex extends Composite {
/*
a bunch of code here for getting data and
populating the tree - works, not at issue or relevant
*/
public V2_M76Rolodex() {
TreeViewModel model = new CustomTreeModel();
CellBrowser browser = new CellBrowser(model, null);
browser.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.ENABLED);
browser.addStyleName("rolodex_cell_browser");
initWidget(browser);
}
}