Viewholder's views association - android-viewholder

I have a RecyclerView whose viewholder contains a button and a textview(Which contains the numberical value starting from 0). I want whenever that button is pressed, the value of the textview gets incremented. I tried using setTag() in onBindView but of no use. The value of the textview gets incremented in one or more viewholders with that approach.
Please help!!

Somehow I managed to achieve the same myself. It is simple as there is no need for setTag() method anymore. Just take a map which stores the key(getAdpaterPosition()) and the value of the textView. When the button is pressed, increment the value of the textview in the map corresponding to the key(position). In the onBindViewHolder(), take the position argument and get value for the corresponding position from the map and set it in the textview. If the key exists in the map, get the value else get default value(0 in my case). In case, one doesnt understand let me know I will submit code here as well.Thanks.

Related

initializing a cocoa IB binding

I have an NSTextField and an NSStepper that I'm trying to bind together. The stepper is setup to go from 0 to 100, and I'd like an initial value of 30.
For the stepper bindings, I have:
value: bind to Object Controller, controller key = selection, model key path = edgeThreshold
For the stepper attributes, I have
min=0, max=100, increment=1, current=30
I've got the text field set up in a similar fashion
bindings, value: bind to Object Controller, controller key = selection, model key path = edgeThreshold
When I run the program, everything works as I'd expect. If I hit the stepper up, the text field increments. If I type in a new value, and then hit the stepper, the value adjusts from my typed in value.
The problem is that the initial value in the text field is nothing (empty), and the initial value of the state appears to be 0. If I hit the stepper after launch, the text field changes from nothing to 1. So I can't figure out where to put the 30, and where the state of this binding really lives. I thought it might be in the object controller, so I set its dictionary to have a keypath and value of "selection.edgeThreshold" and 30...but this did nothing as well.
You don't really need the object controller. You can just bind the values of both the text field and the stepper to the property, edgeThreshold. So, if that property was declared in the app delegate, they would be bound to App Delegate.edgethreshold. If you then set that property to 30 in your applicationWillFinishLaunching method (self.edgethreshold = 30;), the text field will show 30 when the app starts up and the stepper will be set to 30 as well (it doesn't matter what you set the starting value to be in IB, this will override it).
I found a youtube video which pretty much does exactly what I was trying to do:
http://www.youtube.com/watch?v=ESk6YLDtGR8
Rather than instantiate an Object Controller to handle the bindings, I gave my app controller a few properties, and then bound to it. In the app controller's -init method, I set my desired startup values.

reloading tableview after a segue

I have a series of table views that 'drill down' to a final view controller. After the user has filled in a few text fields, it pushes to another one which is a congratulatory screen! Amazing I know. I've put a 'home' button in which (as it is a storyboard) then pushes to the first screen. Unfortunately the table is now not populated.
Do I have to implement some code such as [reload data] in the prepareForSegue method or is there a better/correct way to do it?
Any help would be much appreciated.
Presumably you have an array that provides values for the table and this array gets updated somewhere. Without much else to go on, I'd look at keeping a BOOL value that records whether that array has been changed. Then, in viewDidAppear, call [table reloadData] and reset the flag if there have been changes.

RootViewController need to resort/reload data array xcode 4.3

I'm implementing an example, in that example, I read in data from a database, put it in an array, sort it, and it's displayed using the RootViewController. The DB read and array load happen before the RVC code. So, it works, I get the data in the window created by the RVC and there's a nav controller there as well.
I want to add a button or something to the nav controller so that when you hit it, it sends a value back to the RootViewController.m file, then based on that value, I want to resort the array and display it once again in the RootViewController window.
I'm not sure how to do this. What changes would I have to make to the .xib and the RootViewController.m file?
Please, I'm a confused nube. %-0 Thank you very much.
There's a fair amount to this, so I'll give some general points and if any of them cause problems, it may be easier to work out smaller details.
In you RVC's viewDidLoad method, you can create a button and set it as the right or left button in your controller's navigationItem.
You can associate a tap on that button with a method in your controller that can do whatever you want when the button is tapped. (But a button doesn't send values, really, so you may have to explain more about that idea.)
I assume the RVC has a table view if you're showing array contents, so once the array (mutable array, I'd assume) is re-sorted, you can tell the table view to reload its data.
In answer to your secondary question, once you have resorted your array (or generally updated your data however you wish) you can force the table view to reload programmatically
[tableView reloadData];
Where 'tableView' is your instance variable pointing to your table view

UIPicker and Text and URL

I'm trying to build an app that will display stats for a certain game (I'd rather not say which one). I have most of the app completed, but I have run into a problem with my "Players" page, which is the primary view that loads after viewDidLoad. I've attached a screenshot of how it looks.
(DARN IT. I'm too new to post a pic. Available on request.)
It took some work, but I finally got my UIPickerView into place, and customized the initial options for it. You can't tell from the screenshot, but the picker loads with my player name, and one other. This will change before release.
My problem is that I want users to be able to enter their gamer name(s) in a text field, and have them always selectable from the picker after that. When they select a name in the picker, I need that action to send a string, a URL, with the player name appended to it, to every other view so that all navigation subsequent to choosing a player will show that player's data. This will allow me to load the rest of my server side graphics with ease.
Also, player names must be removable from the picker.
I'm not so lazy as to simply ask for the code, but I can't seem to figure out what components to use, or even find a tutorial that speaks to what I'm doing precisely.
OK what i understand is you want to do two operations on the picker value select.
send the url with the player name.
delete the player name..(if user wants).
Now for this you can add two buttons and as you know the value that are shown in the picker is basically you can store them in am array and load it again on picker.
so now you added two buttons one is for sending data and other is for delete.
on sendData button you can do like this to select the value from picker
NSInteger row;
NSArray *repeatPickerData;
UIPickerView *repeatPickerView; //this your picker, if you defined it already dont do it.
row = [repeatPickerView selectedRowInComponent:0];
self.strPrintRepeat = [repeatPickerData objectAtIndex:row];
now in the "strPrintRepeat" you have the selected value. you can do what ever you want with it.
and on deleting the player name..you can do something like this.
NSInteger row;
NSMutableArray *repeatPickerData; //this should be mutable
UIPickerView *repeatPickerView; //this your picker, if you defined it already dont do it.
row = [repeatPickerView selectedRowInComponent:0];
[repeatePickerData removeObjectAtIndex:row];
now at this point you have the player name removed.
Then you can use your UiPicker delegates to reload the picker with the updated data..
Hope that works..:) enjoy

Making an array of NSRect values in mousedown method

My cocoa app calculates the location of every mousedown event. It also checks whether the location is located inside a rectangle using NSPointInRect and while enumerating over an existing mutable array with values of the rectangles. I'm using an if-statement to add the rectangle values in which the mousedown event is located to a new array (selectedRectangles).
The values are added perfectly to selectedRectangles, only problem is that previous values are overwritten. How can I solve this problem.
PS at the end of the mousedown method I use setNeedsDisplay:YES to update the data (this because selectedRectangles is used in another method).
add the rectangle values…to a new array
Assuming that you're asking a continuation of this question. You don't want to create a new array each time. You want to make an NSMutableArray before any click locations are stored, then use its addObject: method to add a new item on each click.

Resources