I have a customer list. First time it renders with all customers, then I added a filter to list only new customers. Modified the source items with new customers. But it is not rendering in the view. Adapter constructor is called with new set of array. But it is not invoking the method public override int ItemCount. This page will get rendered on screen lock and unlock of device. Please help me here
public class RecyclerViewRenderer : ViewRenderer<RecyclerViewList, RecyclerView>
{
.........
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == RecyclerViewList.ItemsProperty.PropertyName)
{
var items = (Element as RecyclerViewList).Items;
if (items != null)
{
adapter = new RecyclerViewAdapter(items);
adapter.ItemClickEvent += OnItemClick;
adapter.PopUpClickEvent += OnPopUpClick;
recyclerViewCustomers.SetAdapter(adapter);
adapter.NotifyDataSetChanged();
// Task.Delay(500);
}
}
}
......
}
Related
I have a PopUpWindowShowAction that operates on the current record.
If there is no current record then I want the action disabled.
This is because if there is no record the PopUpWindowShowAction will fail.
Here is my simplified controller
using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.ExpressApp.Editors;
using System;
using System.Linq;
using System.Windows.Forms;
namespace MyNamespace
{
public partial class JobWorkflowController : ViewController
{
PopupWindowShowAction actWorkflow;
public JobWorkflowController()
{
TargetObjectType = typeof(IWorkflow);
actWorkflow = new PopupWindowShowAction(this, "Workflow", "Admin")
{ AcceptButtonCaption = string.Empty, ActionMeaning = ActionMeaning.Accept, CancelButtonCaption = null, Caption = "Workflow", ConfirmationMessage = null, ImageName = "Workflow", Shortcut = "F7", ToolTip = null };
actWorkflow.CustomizePopupWindowParams += actWorkflow_CustomizePopupWindowParams_1;
actWorkflow.Execute += actWorkflow_Execute_1;
actWorkflow.Cancel += actWorkflow_Cancel;
}
private void actWorkflow_CustomizePopupWindowParams_1(object sender, CustomizePopupWindowParamsEventArgs e)
{
if (View.CurrentObject is not IWorkflow wf)
{
// causes an error because the view is not set
return;
}
// code to create the popup view
}
private void actWorkflow_Execute_1(object sender, PopupWindowShowActionExecuteEventArgs e)
{
// code
}
private void actWorkflow_Cancel(object sender, EventArgs e)
{
// code
}
protected override void OnActivated()
{
base.OnActivated();
View.CurrentObjectChanged += View_CurrentObjectChanged;
View_CurrentObjectChanged(View, new EventArgs());
}
private void View_CurrentObjectChanged(object sender, EventArgs e)
{
actWorkflow.Enabled["HasCurrent"]= View.CurrentObject != null;
}
protected override void OnDeactivated()
{
View.CurrentObjectChanged -= View_CurrentObjectChanged;
base.OnDeactivated();
}
}
}
The View_CurrentObjectChanged event fires but the action does not disable.
[Update]
I tried Michael's suggestion but the action des not disable.
Put this in your constructor
actWorkflow.SelectionDependencyType = SelectionDependencyType.RequireSingleObject
And it will only be active when a single object is selected. If you'd like to have one or more objects selected it's:
actWorkflow.SelectionDependencyType = SelectionDependencyType.RequireMultipleObjects;
You'll have no need to subscribe to the CurrentObjectChanged event.
I am trying to understand how a wpf custom control could be written in F#.
As an example, I have the following C# code for a drag and drop on a canvas (in C#). It inherits from ListBox. I'm not looking for anybody to rewrite this. But I'm at a loss as to how it would be implemented in Elmish.wpf since there is no xaml to deal with. (I believe a Custom Control does not have a XAML interface).
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace Stargate.XI.Client.Views.CustomControls
{
public delegate void DropCompletedEventHandler(object sender, DropCompletedEventArgs e);
// To add a custom DropCompletedEvent to an ItemsControl, I would either have to have an attached property, as in
// https://stackoverflow.com/questions/15134514/attached-behavior-handling-an-attached-event-in-wpf
// or subclass an ItemsControl as below. Creating a simple custom control, like here, seems cleaner.
// Note: ItemsControl can't select items, only present collections. Only a Selector or one of it's descendants can select items
// Hence, only the ListBox or its derivative,ListView, have Selector's.
public class ChartCanvas : ListBox
{
public event EventHandler PlayMusicEvent;
public event EventHandler PauseMusicEvent;
public event EventHandler StopMusicEvent;
public event EventHandler DisposeMusicEvent;
public event EventHandler DisposePosterEvent;
#region DropCompletedEvent
// Create a custom routed event by first registering a RoutedEventID
// This event uses the bubbling routing strategy
public static readonly RoutedEvent DropCompletedEvent = EventManager.RegisterRoutedEvent(
"DropCompleted", RoutingStrategy.Bubble, typeof(DropCompletedEventHandler), typeof(ChartCanvas));
// Provide CLR accessors for the event. The RoutedEventHandler, e.g., "DropCompleted" is used in the xaml declaration for the ImageCanvas.
public event DropCompletedEventHandler DropCompleted
{
add { AddHandler(DropCompletedEvent, value); }
remove { RemoveHandler(DropCompletedEvent, value); }
}
// This method raises the DropCompleted event
public void RaiseDropCompletedEvent(object datatype)
{
RaiseEvent(new DropCompletedEventArgs(DropCompletedEvent, datatype));
}
#endregion
public ChartCanvas()
{
AllowDrop = true;
DragEnter += IC_DragEnter;
Drop += IC_Drop;
DragOver += IC_DragOver;
DragLeave += IC_DragLeave;
}
private void IC_DragLeave(object sender, DragEventArgs e)
{
e.Handled = true;
}
private void IC_DragOver(object sender, DragEventArgs e)
{
e.Handled = true;
}
private void IC_Drop(object sender, DragEventArgs e)
{
var data = e.Data.GetData(DataFormats.Text);
var dragSource = e.Data.GetData("DragSource");
RaiseDropCompletedEvent(data);
}
private void IC_DragEnter(object sender, DragEventArgs e)
{
e.Handled = true;
}
#region PlayMovie
private ICommand _playMovie;
public ICommand PlayMovieCommand
{
get
{
if (_playMovie == null)
{
_playMovie = new RelayCommand(
p => true,
p => this.PlayMovie());
}
return _playMovie;
}
}
private void PlayMovie()
{
PlayMusicEvent?.Invoke(this, EventArgs.Empty);
}
#endregion
#region PauseMovie
private ICommand _pauseMovie;
public ICommand PauseMovieCommand
{
get
{
if (_pauseMovie == null)
{
_pauseMovie = new RelayCommand(
p => true,
p => this.PauseMovie());
}
return _pauseMovie;
}
}
private void PauseMovie()
{
PauseMusicEvent?.Invoke(this, EventArgs.Empty);
}
#endregion
#region StopMovie
private ICommand _stopMovie;
public ICommand StopMovieCommand
{
get
{
if (_stopMovie == null)
{
_stopMovie = new RelayCommand(
p => true,
p => this.StopMovie());
}
return _stopMovie;
}
}
private void StopMovie()
{
StopMusicEvent?.Invoke(this, EventArgs.Empty);
}
#endregion
public bool Dispose
{
get { return (bool)GetValue(DisposeProperty); }
set { SetValue(DisposeProperty, value); }
}
// Using a DependencyProperty as the backing store for Dispose. This enables animation, styling, binding, etc...
public static readonly DependencyProperty DisposeProperty =
DependencyProperty.Register("Dispose", typeof(bool), typeof(ChartCanvas), new PropertyMetadata(false,
(s,e) =>
{
ChartCanvas chartcanvas = s as ChartCanvas;
chartcanvas.DisposeMusicEvent?.Invoke(chartcanvas, EventArgs.Empty);
chartcanvas.DisposePosterEvent?.Invoke(chartcanvas, EventArgs.Empty);
}
));
}
}
Any suggestions to this newbie as to how to approach this would be much appreciated.
TIA
I want to review the selected item from listview, provided that when filtering, the selected visible element is selected
This code works well if the item is selected without filtering.
If the filtering process is complete, it will display elements that are not visible in the same position
private List<string> itemlist;
listviewa.ItemClick += Listnames_ItemClick;
private void Listnames_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string itemcheck = itemlist[e.Position].ToString();
Toast.MakeText(Activity, itemcheck, ToastLength.Short).Show();
}
//filter
void _SV_QueryTextChange(object sender, Android.Support.V7.Widget.SearchView.QueryTextChangeEventArgs e)
{
_adapter.Filter.InvokeFilter(e.NewText);
}
i changed the process
enter code here
private List itemlist;
listviewa.ItemClick += Listnames_ItemClick;
private void Listnames_ItemClick(object sender, AdapterView.ItemClickEventArgs e)
{
string itemcheck = itemlist[e.Position].ToString();
Toast.MakeText(Activity, itemcheck, ToastLength.Short).Show();
}
//filter
void _SV_QueryTextChange(object sender, Android.Support.V7.Widget.SearchView.QueryTextChangeEventArgs e)
{
_adapter.Filter.InvokeFilter(e.NewText);
}
I tried to implement a solution, in Xamarin.Forms for iOS, which notified me if the user changed the authorization state for the location (see the code below). Because the first time if the app starts is the authorization denied or not determined (I don't know this exactly).
But it seems not to work, the event will be triggered only before the user tab on allow or denied.
Maybe someone else have an better idea or an other solution for this. I have oriented myself on here.
My class with the map in it (the view or what ever):
public partial class MapsView : ContentPage
{
ILocation locService;
public MapsView()
{
...
locService = DependencyService.Get<ILocation>();
// Create method to listen for the event.
locService.AuthorizationChanged += MapsView_AuthorizationChanged;
}
private void MapsView_AuthorizationChanged(object sender, EventArgs args)
{
// Do stuff with the location.
}
}
My Interface for the dependency injection:
public delegate void AuthorizationChangedEventHandler(object sender, EventArgs args);
public interface ILocation
{
event AuthorizationChangedEventHandler AuthorizationChanged;
void OnAuthorizationChanged(EventArgs e);
}
And the iOS specific code:
public class Location : ILocation
{
public Location()
{
var manager = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
manager.RequestWhenInUseAuthorization();
manager.AuthorizationChanged += (sender, args) => {
// Trigger event.
OnAuthorizationChanged(new EventArgs());
};
}
public event AuthorizationChangedEventHandler AuthorizationChanged;
public void OnAuthorizationChanged(EventArgs e)
{
AuthorizationChanged?.Invoke(this, e);
}
}
I am creating a Twitter client using Fabric but I can not create a custom onClick.
I created this custom adapter and tried to create a OnClickListener but not working. Always open in browser tweet.
public class TweetAdapter extends TweetTimelineListAdapter {
public ArrayList<Long> tweetIds=new ArrayList<Long>();
public TweetAdapter(Context context, Timeline<Tweet> timeline) {
super(context, timeline);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
Object rowView = convertView;
final Tweet tweet = (Tweet)this.getItem(position);
if(convertView == null) {
rowView = new CompactTweetView(this.context, tweet);
} else {
((BaseTweetView)convertView).setTweet(tweet);
((View)rowView).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
tweetIds.add(tweet.getId());
}
});
}
return (View)rowView;
}
}
In BaseTweetView class it is the function type OnClickListener but in this case I can't think of any idea to overwrite.
private void setPermalinkLauncher() {
BaseTweetView.PermalinkClickListener listener = new BaseTweetView.PermalinkClickListener();
this.setOnClickListener(listener);
this.contentView.setOnClickListener(listener);
}
class PermalinkClickListener implements OnClickListener {
PermalinkClickListener() {
}
public void onClick(View v) {
if(BaseTweetView.this.getPermalinkUri() != null) {
BaseTweetView.this.scribePermalinkClick();
BaseTweetView.this.launchPermalink();
}
}
}
Any ideas? Thanks
Finally I made this works using a custom Adapter (very similar that the one you use in the question). This adapter obtains the resulting view from super implementation and adds an onClickListener to overrides the fabric defaults one:
class CustomTweetTimelineListAdapter extends TweetTimelineListAdapter {
public CustomTweetTimelineListAdapter(Context context, Timeline<Tweet> timeline) {
super(context, timeline);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
//disable subviews to avoid links are clickable
if(view instanceof ViewGroup){
disableViewAndSubViews((ViewGroup) view);
}
//enable root view and attach custom listener
view.setEnabled(true);
view.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String tweetId = "click tweetId:"+getItemId(position);
Toast.makeText(context, tweetId, Toast.LENGTH_SHORT).show();
}
});
return view;
}
//helper method to disable subviews
private void disableViewAndSubViews(ViewGroup layout) {
layout.setEnabled(false);
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
disableViewAndSubViews((ViewGroup) child);
} else {
child.setEnabled(false);
child.setClickable(false);
child.setLongClickable(false);
}
}
}
}
Full code example here.
Hope it helps.