Arraylist and ListView - arraylist

I have a ListView, I created a custom adapter because in every row there must be two ImageView.
My aim is to set on clicklistener one of them, and when I click it a new row must be created in a certain position in the list.
I know that to achieve this I have to set onclickListener the imageView inside the adapter class, but how can I get access to the ArrayList of the ListView so that I can create new rows?

This is the onClick() method in the onClickListener that you need:
public void onClick(View v){
mArrayList.add(<some new data>, <the index of the row> + 1);
mBaseAdapter.notifyDatasetCahged();
}

Related

In UWP, how to skip tab key navigation for an UserControl and all of its child element?

In UWP, I want to handle and skip the tab key navigation for particular set of controls dynamically.
For e.g., I've two user controls (Both have lot of children which will be added dynamically) in my main page and want to skip tab key navigation for one usercontrol dynamically on specific scenario for a moment.
So I've tried to set "IsTabStop" as false to that UserControl. But which is not effective on its child controls. Still tab key focus moved inside the children of that UserControl.
Note: If I set "IsEnabled" as false, then its working. But I don't want to use because it affects Visual appearance.
Thanks in advance.
There is no IsTabStop property in StackPanel class. The IsTabStop property is defined in Windows.UI.Xaml.Controls.Control class, and the StackPanel class is not inherited from Control class, either directly or indirectly. You can not use IsTabStop property to set a StackPanel instance.
Therefore, if you want to skip tab key navigation for one stackpanel, you need to set the IsTabStop property to False in each control in the stackpanel.
Update:
By testing, the child elements in a UserControl can not inherit the value of IsTabStop property. Therefore, you cannot skip tab key navigation for all the child elements in a UserControl by setting the IsTabStop property to False.
You could use a method defind in your UserControl class to set IsTabStop to false for every item in your UserControl.
For example:
MyUserControl.cs
public void SetIsTabStop(bool flag)
{
var result = VisualTreeFindAll<Control>(this);
foreach (var item in result)
{
item.IsTabStop=flag;
}
}
private IList<T> VisualTreeFindAll<T>(DependencyObject element)
where T : DependencyObject
{
List<T> retValues = new List<T>();
var childrenCount = VisualTreeHelper.GetChildrenCount(element);
for (var i = 0; i < childrenCount; i++)
{
var child = VisualTreeHelper.GetChild(element, i);
var type = child as T;
if (type != null)
{
retValues.Add(type);
}
retValues.AddRange(VisualTreeFindAll<T>(child));
}
return retValues;
}
Use the name of a UserControl instance to call the SetIsTabStop(bool flag) method with False.
userControlName.SetIsTabStop(false);
Update:
Maybe you could try the following workaround.
Add the KeyDown event handler for the UserControl in your Page.
private void UserControl_KeyDown (object sender, KeyRoutedEventArgs e)
{
if (e.Key == Windows.System.VirtualKey.Tab)
{
e.Handled = true;
button1.Focus(FocusState.Keyboard);
}
}
You need to let the first control except the UserControl and all its child controls get the focus, then the key navigation will skip the child controls in the UserControl except the first child control in the UserControl.

Visibility of expanding last view in the expandable RecyclerView

I want the things in the last expandable item to be fully visible when it is clicked,Now what is happening means when I click on last item it expands down, but I manually need to scroll up again to see the the things inside the expanded item.How can the last expandable item be fully visible.
I am using Recyclerview.
I have found the solution which I wanted, I used
recyclerView.smoothScrollToPosition(selectedPosition);
after setting the adapter. So now the things in the last expandable item is fully visible when it is clicked.
Just a supplementary:
If you use h6ah4i/advrecyclerview, you can use the following code snippet:
#Override
public boolean onHookGroupExpand(int groupPosition, boolean fromUser) {
// NOTE21: collapse all other groups when one item expand.
mExpMgr.collapseAll();
// NOTE21: Visibility of expanding last view in the expandable recyclerview
if (groupPosition == getGroupCount() - 1) {
mRecyclerView.smoothScrollToPosition(groupPosition + getChildCount(groupPosition));
}
return true;
}

Looping through an array of nodes to add a MouseEvent that affects an external variable

I have an arraylist of HBox nodes that need to work sort of like a set of radio buttons. Clicking on any of the nodes will update an int value corresponding with the clicked-on node's position in the array.
It's an array list because the number of HBox nodes needs to be dynamic and determined upon runtime based on arguments. Each HBox is identical in format but the contents of the labels inside are unique.
Looping through the arraylist (arrayOfHBox) to add a Mouse click event to each node produces the problem of inner classes not accepting non-final variables (so inside the mouse event I can't tell what position of the array I'm at). I understand the reasons why this must happen, but I'm not sure of an alternative approach to get around it.
int selectedIndex=-1; //the int to determine which "radio button" HBox is clicked
for (int i=0;i<arrayOfHBox.size();i++)
{
arrayOfHBox.get(i).addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent event)
{
selectedIndex=i; //Won't compile
event.consume();
}
});
}
The question then: is there a way to add mouse handlers to all the HBox nodes where each would set an external variable equal to the clicked-upon node's position in the array?
Then e. g. use a final intermediate variable like
int selectedIndex=-1; //the int to determine which "radio button" HBox is clicked
for (int i=0;i<arrayOfHBox.size();i++)
{
final int index = i;
arrayOfHBox.get(i).addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>()
{
#Override
public void handle(MouseEvent event)
{
selectedIndex=index; //Won't compile
event.consume();
}
});
}
or work on object level, use event.getSource() to determine the source and pick the hbox as item of the arraylist.

Eclipse plugin development - How to add Radio buttons in WizardNewFileCreationPage

I am using WizardNewFileCreationPage to create a New File
public void addPages() {
mainPage = new WizardNewFileCreationPage("FILE", getSelection());
mainPage.setTitle("New File");
mainPage.setDescription("Add new file");
addPage(mainPage);
}
I want to add some Radio Buttons to it representing file extensions in this wizard so that users can select one of them as a file extension.
The WizardNewFileCreationPage is not meant to be extended with custom controls. From its JavaDoc:
Subclasses may override
getInitialContents
getNewFileLabel
Subclasses may extend
handleEvent
If you still want to add the radio buttons 'at your own risk', you can try to override createAdvancedControls and append you controls to the parent after calling super.
protected void createAdvancedControls(Composite parent) {
super.createAdvancedControls( parent );
Button radioButton = new Button( parent, SWT.RADIO );
// ...
}
Note that the layout of parent (currently) is a single-columned GridLayout, set the layout data accordingly.

Re-render a VariableSizedWrapGrid

Once a VariableSizedWrapGrid has rendered its content, is there a way to refresh its layout so that it re-renders and re-applies the sizes if they have changed?
For example, the first item is twice the size of the rest, then I change the column and row span values in the view model. Now I want to invoke the grid to re-render.
Here's a simple way:
public void Update(GridView gridView)
{
if (!(gridView.ItemsPanelRoot is VariableSizedWrapGrid))
throw new ArgumentException("ItemsPanel is not VariableSizedWrapGrid");
foreach (var container in gridView.ItemsPanelRoot.Children.Cast<GridViewItem>())
{
var data = container.Content as Common.ModelBase;
VariableSizedWrapGrid.SetRowSpan(container, data.RowSpan);
VariableSizedWrapGrid.SetColumnSpan(container, data.ColSpan);
}
gridView.ItemsPanelRoot.InvalidateMeasure();
}
Assuming Windows.UI.Xaml.Controls.GridView as ItemsControl
Assuming Windows.UI.Xaml.Controls.VariableSizedWrapGrid as ItemPanel
I integrated it into the custom grid like this: http://codepaste.net/aopvks
Best of luck!