I'm unable to understand the control flow of the recycler view in android.
we make a call to the adapter class in mainActivity.kt but where are the function calls for the three overridden methods of adapter class.
because why and where they (getItemCount(),onCreateViewHolder()) return values
Related
I have the following code snippet in Vaadin 8 to navigate to ShipmentView. The shipment view is registered with two parameter constructor:
navigator.addView("shipment", new ShipmentView("name", "shipmentId"));
navigator.navigateTo("shipment");
During the migration process, we decide to migrate ShipmentView later and use MprRouteAdapter first.
if the view does not require the two parameter constructor, we can have the following adapter and navigate with code UI.getCurrent().navigate(ShipmentViewRoute .class)).
#Route(value = "shipment", layout = MainLayout.class)
public class ShipmentViewRoute extends MprRouteAdapter<ShipmentView> {
public ShipmentViewRoute () {
this.setSizeFull();
}
}
With the two parameter "name"and "shipmentId", how can I create the Adapter?
Thanks you in advance.
I think the most straightforward way is just to hard-code those parameters in the constructor (or fetch them from wherever you would get them from when initializing the navigator in the old code).
I want to use my Viewmodel instance in Adapter class but it doesn't find the viewModel delegate.It works in fragment and activities but not found in adapter classes.
private val queueViewModel: QueueViewModel by viewModels {
QueueViewModel.QueueDataViewModelFactory((requireActivity().application as DownloadManagerApplication).repository)
}
unresolved reference: viewModels
I'm converting an Android application to React Native and I'm new to this react-native technology.
In my android application, I have used the Singleton object to store some data. I just want to create the same for the react-native application. Inside the Java singleton object, it has a list
eg : public List<PharmacyLocationChecklistsDTO> pharmacyLocationChecklistsDTOS;.
Scenario: In my java application has wizard this singleton object store all the data of that wizard view. I have already implemented the wizard in my react native application, but I don't know how to store data until the user completes the task.
How could I create this object in my react-native app or is there any other way to handle this scenario?
Response,
"pharmacyLocationChecklistsDTOS": [
{
"chelistid": 232,
"ireqstId": 5,
"checklistName": "E",
"validity": "Invalid",
"remark": null
}
]
Sample Java Object,
public class PharmacyLocationChecklistsDTO{
public int chelistid;
public int ireqstId;
public String checklistName;
public String validity;
public Object remark;
}
public class Root{
public List<PharmacyLocationChecklistsDTO> pharmacyLocationChecklistsDTOS;
}
This is the job of a state management system.
There are popular options like Redux, MobX, React's Context API, Recoil. They will allow multiple components to consume the same state.
I'd suggest to go through them and see which caters to your needs the most.
There is an application consisting of UI Controller and Processor. UI Controller receives requests from user and passes them to Processor. Processor has a simple interface: just one Process(input) method.
Processor could be a singleton or not, and UI Controller should not know that.
Now, Processor should send back some progress notifications to UI Controller. While I could add an event to Processor interface that UI Controller could subscribe to, I don't know how to make it work in case of a singleton Processor:
subscription to the progress event should happen only once
Processor should not hold references to UI Controller instances so that memory can be freed when needed
progress event handlers are UI-specific, so they cannot be takes out of UI Controller
How would you design it so that UI Controller does not care whether Processor is singleton or not?
Create UIController with a reference to a Processor interface (constructor injection). UIController doesn't know if the implementation of the interface is a singleton or not. Change the Processor method to Process(input, notifyCallback) so Processor can make notifications without holding UIController references. notifyCallback will be a function or interface implemented in UIController (depending on language).
You can achieve your desired result by having a static event in Processor class and registering it in UIController.
private delegate void ProgressDelegate(Processor process, object data);
class Processor
{
public static event ProgressDelegate ProcessProgress;
private void method()
{
//....your code
if (ProcessProgress != null)
ProcessProgress(this, new object());
}
}
The event can be registered using UIController without worrying about the object. Once the event is fired, you will pass the processor object and the UIController can proceed.
class UIController
{
static UIController()
{
Processor.ProcessProgress += new ProgressDelegate(HandleProcessProgress);
}
static void HandleProcessProgress(Processor p, object data)
{
}
}
I am developing a Windows Phone 7 app and am using the MVVM pattern. I have a need to pass a parameter to the contructor of the ViewModel for a page. All my datacontexts and binding are done in XAML. Through my research I've seen that I need to do so using a dependency injector such as NInject.
Here's a little detail on whats going on:
I have a page with a ListPicker that lists various tasks. Each task has a unique TaskID. When an item is selected I need to open another page that will show the selected Tasks detail. My ViewModel and binding is all done and works if I use a static TaskID in the ViewModel but of course I need to use a variable.
I've setup NInject in the project and the various classes needed such as ViewModelLocator and my NInjectModule as shown here:
public class LighthouseNInjectModule : NinjectModule
{
public override void Load()
{
this.Bind<TaskViewModel>().ToSelf().WithConstructorArgument("TaskID", 2690);
}
}
Note that I have hardcoded a TaskID here and using this code this value properly gets injected into my constructor. Of course, this is hardcoded and I need to get the TaskID for the selected ListPicker item. I know how to get the selected ID from the ListPicker but how do I make NInject aware of it so when my class constructor is run it will have the correct value?
Here is the basic definition of my ViewModel class showing use of the Injector attribute.
public class TaskViewModel : INotifyPropertyChanged
{
[Inject]
public TaskViewModel(int TaskID)
{
//run function to get data using TaskID
}
}
WithConstructorArgument has another oveload that accepts a lazy evaluated Func<Context, object>.