can anyone please help me with this I want to implement the Alphabetic index with Recyclerview in Xamarin android.
You must first sort our list
example:
List<Email> emails = new List<Email>();
emails.Add(new Email { Address="Test1#contoso.com" , CreateTime=new DateTime(2016, 7, 14, 3, 15, 0) });
emails.Add(new Email { Address = "Test2#contoso.com", CreateTime = new DateTime(2013, 8, 11, 3, 15, 0) });
emails.Add(new Email { Address = "Test3#contoso.com", CreateTime = new DateTime(2017, 6, 13, 3, 15, 0) });
emails.Add(new Email { Address = "Test4#contoso.com", CreateTime = new DateTime(2011, 8, 14, 3, 15, 0) });
emails.Add(new Email { Address = "Test5#contoso.com", CreateTime = new DateTime(2013, 9, 16, 3, 15, 0) });
emails.Add(new Email { Address = "Test6#contoso.com", CreateTime = new DateTime(2015, 1, 15, 3, 15, 0) });
emails.Sort((x, y) => DateTime.Compare(x.CreateTime, y.CreateTime));
var recyclerView = FindViewById<RecyclerView>(Resource.Id.recyclerView);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(emails, this);
recyclerView.SetLayoutManager(new LinearLayoutManager(this));
recyclerView.SetAdapter(adapter);
Related
I have following codes in javascript
var ArrayLogs = [1, 3, 5, 4, 9, 11, 0, -4, -10];
var newLogArrays = [];
ArrayLogs.reduce(function(result, value, index, array) {
if (index % 2 === 0){
newLogArrays.push(array.slice(index, index + 2));
}
return newLogArrays;
}, []);
Above method outputs:
[[1,3],[5,4],[9,11],[0,-4],[-10]]
I am looking equivalent code in Dart, I know there is reduce method in dart as well, but I am not sure how to use to get similar result as javascript.
Any help will be highly appreciated.
Thanks
If you just want to do it using Dart only, you can do something like the following:
void main() {
final arrayLogs = [1, 3, 5, 4, 9, 11, 0, -4, -10];
final result = arrayLogs.fold<List<List<int>>>([], (list, element) {
if (list.isEmpty || list.last.length > 1) {
return list..add([element]);
} else {
return list..last.add(element);
}
});
print(result);
// [[1, 3], [5, 4], [9, 11], [0, -4], [-10]]
}
I am sure there are some packages which can do this more automatically or cleaner.
i try to include a indicator in my ea, but i still get as results always "1.797693134862316e+308" if i print out the copied datas from the icustom-function.
int iCustomHandle;
double trendline_buy_signal[];
double trendline_sell_signal[];
double trendline_sl_price[];
double trendline_tp1_price[];
double trendline_tp2_price[];
double trendline_tp3_price[];
int OnInit()
{
iCustomHandle = iCustom(symbol, time, "\\Indicators\\Market\\myindicator.ex5");
if(iCustomHandle == INVALID_HANDLE){ return(INIT_FAILED); }
return (INIT_SUCCEEDED);
}
void OnTick()
{
int valueDistance = 0;
int calculatedInd = BarsCalculated(iCustomHandle);
ArraySetAsSeries(trendline_buy_signal, true);
ArraySetAsSeries(trendline_sell_signal, true);
ArraySetAsSeries(trendline_sl_price, true);
ArraySetAsSeries(trendline_tp1_price, true);
ArraySetAsSeries(trendline_tp2_price, true);
ArraySetAsSeries(trendline_tp3_price, true);
int copied;
copied = CopyBuffer(iCustomHandle, 2, 0, calculatedInd, trendline_buy_signal);
copied = CopyBuffer(iCustomHandle, 8, 0, calculatedInd, trendline_sell_signal);
copied = CopyBuffer(iCustomHandle, 9, 0, calculatedInd, trendline_sl_price);
copied = CopyBuffer(iCustomHandle, 10, 0, calculatedInd, trendline_tp1_price);
copied = CopyBuffer(iCustomHandle, 11, 0, calculatedInd, trendline_tp2_price);
copied = CopyBuffer(iCustomHandle, 12, 0, calculatedInd, trendline_tp3_price);
Print("calculatedInd:",calculatedInd," > iCustom bufferr: buy_signal:", trendline_buy_signal[valueDistance],
" > sell_signal:",trendline_sell_signal[valueDistance],
" > sl_price:",trendline_sl_price[valueDistance],
" > tp1:",trendline_tp1_price[valueDistance],
" > tp2:",trendline_tp2_price[valueDistance],
" > tp3:",trendline_tp3_price[valueDistance]);
}
What is the reason for it and how i can solve it?
Thanks a lot!
you get EMPTY_VALUE so You should use something like this:
if(Value != EMPTY_VALUE)
Print(Value);
first thing first my question is very similar to this one. In fact, it's the same thing, except that I need to group every user like this below:
Everyone under 12 (exclusive)
Then, from 12 - 19
Then, from 20 - 29
...
More than 80 (inclusive)
Based on the answer from dasblinkenlight in the other question, I was able to do:
var ageStats = vModel
.GroupBy(l => 10 * (l.Age / 10))
.OrderBy(x => x.Key)
.Select(g => new
{
Name = g.Key,
Count = g.Select(l => l.Age).Count()
}).ToList();
For a result set of :
0-9
10-19
20-29
...
So what should I do to accomplish the pattern I have to ?
Thank you very much !!
var ages = new[] { 12, 19, 29, 80 };
var grouped = ages.Select(r => new {
Name = r,
Count = vModel.Count(x => x.Age >= r)
});
try this, but i don't know the performance
var ages = new int[12, 19, 29, 80];
var func = new Func<int, int>(a=>{
for(var i = 0; i<ages.Length; i++){
if(a<ages[i])
continue;
return i;
}
return 0;
});
vModel.GroupBy(m=>func(m.Age))....
You could use approach mentioned here and use this code:
var ages = new List<int> { 12, 19, 29, 39, 49, 59, 69, 80, int.MaxValue};
var categories = vModel.GroupBy(item => ages.FirstOrDefault(ceil => ceil >= item));
I have run in to issue that days that have to be disabled are shifted to the next day.
The idea is that day that does not exist in our booking object or have a value less than 1 should be disabled on calendar.
here is simplified version of my script and demonstration on jsfiddle:
var bookings = {
"2012-09-01": 24,
"2012-09-03": 31,
"2012-09-05": 27,
"2012-09-06": 9,
"2012-09-07": 18,
"2012-09-08": 0,
"2012-09-10": 20,
"2012-09-12": 19,
"2012-09-13": 0,
"2012-09-14": 9,
"2012-09-15": 24,
"2012-09-17": 19,
"2012-09-19": 28,
"2012-09-20": 15,
"2012-09-21": 12,
"2012-09-22": 25,
"2012-09-24": 19,
"2012-09-26": 0,
"2012-09-27": 0,
"2012-09-28": 0,
"2012-09-29": 0
};
function MyEvent(date)
{
bookings = bookings || {};
this.date = date.toISOString().substr(0, 10);
this.display = (typeof bookings[this.date] == 'number' && bookings[this.date] > 0);
return this;
}
MyEvent.prototype.toArray = function () {
return [this.display, null, null];
};
$(function ()
{
$('#eventCalendar').datepicker({
dateFormat: "yy-mm-dd",
firstDay: 1,
defaultDate: "2012-09-24",
beforeShowDay: function (date)
{
return new MyEvent(date).toArray();
}
}
);
});
Can some one suggest me what am I doing wrong or is it a bug?
It was a little struggle, but is not a bug.
There is a problem using:
date.toISOString()
the operation can return a different date (for example next day) from the original date passed from the plug in, because the function ignores timezone offsets
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Date/toISOString
so your condition will not work well.
Here is a working fiddle the is not using that function: http://jsfiddle.net/nBejK/2/
I have the following query:
view.reduce.group_level(5).keys
which returns:
[["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 13], ["1f9c79a33f399a7937d880c5f31e8dbc", 2011, 12, 29, 14], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 13], ["c38332ffc275b6c70bcf06ffc39ddbdd", 2011, 12, 29, 14]]
The first key is an id and the other keys are year, month, day, hour
I would like all the rows between 2010 and 2013. So I want to ignore the first key.
The problem is that i need to set the first parameter to get the results but i want to get all the results for all the keys.
for example: view.reduce.group_level(5).startkey(["every_possible_key", 2010]).endkey(['every_possible_key", 2013, {}])
If i leave the first key blank than i get nothing. If i give it "\u9999" than i get everything and it ignores the 2nd key.
Somebody knows what I am doing wrong?
Thanks a lot.
map:
function(d) {
if (d['type'] == 'State' && d['driver_id'] && d['name'] && d['created_at']) {
var dt = new Date(d.created_at);
emit([d.driver_id, dt.getFullYear(), dt.getMonth() + 1, dt.getDate(), dt.getHours()], d.name);
}
}
reduce:
function(k,v,r) {
var result = {
'hire': 0, 'hired': 0, 'arrived': 0, 'pick up': 0, 'drop off': 0,
'missed': 0, 'rider cancel': 0, 'driver cancel': 0, 'no show': 0,
'avail': 0, 'unavail': 0, 'other': 0
};
if (r) {
var row = null;
for (i in v) {
row = v[i];
for (j in row) {
result[j] += row[j];
}
}
} else {
for (i in v) {
if (result[v[i]] != null) {
result[v[i]] += 1;
} else {
result['other'] += 1;
}
}
}
return result;
}
What you're "doing wrong" is to use a key you don't need in your query as the first key of your view.
If you need it for another query, create another view.