How to create a list of items where each row is composed of an image, text and a radio button? - blackberry

I'm working with BlackBerry API 7.0 and I'm trying to display a list of countries, each row must display, in the following order, a country flag, the name of the country and a RadioButtonField to indicate the state of selection, something like this:
| -icon- -text- -radio button- |
I've been looking for an example of this kind of control, but haven't found a similar approach.
A RadioButtonGroup only hold RadioButtonFields so, as far as I understand, it isn't what I need.
I know there's the ListField but I haven't found an example of a Manager that implements the look & feel I'm trying to achieve, specially since I have to handle the selection of the RadioButtonField I'm not sure if adding a RadioButtonGroup with a single RadioButtonField to each row is the correct approach (specially since a RadioButtonGroup is not allowed on the Manager class) and if so, how can I handle the state of selection for a radio button on each row?.
What is the best way to implement the design I need? Can this be done with a RadioButtonGroup? Or is it possible to use a custom Manager class for this?

I know that Blackberry has their own API's for various things - and I have absolutely no experience with any of those.
But the standard List class offers a way to use images in your list.
You just have to create two arrays first. One with the string-elements and one with the image-elements.
String[] theStrings = {"1st item", "2nd item", "3rd item"};
try {
image1 = Image.createImage("1stimage.png");
image2 = Image.createImage("2ndimage.png");
image3 = Image.createImage("3rdimage.png");
} catch (Exception e) {}
Image[] theImages = {image1, image2, image3};
int listType = List.IMPLICIT;
List myList = List("List title", listType, theStrings, theImages);
http://docs.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/javax/microedition/lcdui/List.html
(If this answer is completely wrong in relation to BlackBerry API 7.0, then the "java-me" tag should probably be removed from the question).

Related

Telerik Kendo Chart : How to bind the chart to a string type

I've been stuggling for a moment and I'm unable to find anything related to that. I'm a total newbie with Kendo, and sadly I was not able to find anything that could help my question, documentation, forums and all of that : they haven't helped at all.
Situation :
I have a viewmodel in my ASP .NET app. I'm trying to make a chart out of one of the proripeties called "Type". This propriety represent a type of data - let's say fruits, like "Banana", "Apple" etc.
This type contains only and only one type at the time. It cannot contain something like "Apple and bananas". It's always a string, too.
This proriety is part of a larger model. But I'm only interested in this one.
Now, what I like to do :
I'd like to make a chart, using Kendo, from that propriety.
That means, I have to bind my chart to my model, and then, it will be able to know how many time some of those Types were used.
Like, example, If I have three objects :
Name : "Mjuzl"
Type : "Potato"
Name : "Uijqf"
Type : "Apple"
Name : "Zjli"
Type : Potato"
I'd like my char to count that my model used the type Potato twice, and the type Apple once.
I know how to get my datasource that contain all of the objects that use my model. (I have already used Kendo Grid just before but it's so simplier tbh) My issue right now, is that I have no idea - and I wasnt' able to find any - how to actually display what I want in my chart. I say it again, they are strings. I know how to get my datasource. I don't know how to actually show what I want to show. (Should I use columns ? sections ? I don't know)
Do I need to build a JSON from my controller that will ask the database to count ? Does Kendo is able to do it by it's own ? I'm so lost, I have no idea what Kendo is actually waiting for to make my chart working. The documentation isn't helping at all. I've been researching for a while, I haven't found anything that describes the exact same problem. And I've been searching for days.
Very badly drawn image I've done to put a picture on my problem :
I don't ask to do it for me, I ask for a path. A way to do it.
Thanks.
One way would be to create a view model specifically for your chart, and you can populate that view model based on your data.
Roughly (untested code - just to give you an idea), something like this:
public class MyChartViewModel
{
public int TypeCount { get; set; }
public string TypeName { get; set; }
}
and then in your read method for the chart where you are populating MyChartViewModel:
var myExistingDataModel = howeverYouGetYourDataHere;
var model = new MyChartViewModel();
var distinctTypes = myExistingDataModel.Select(x => x.Type).Distinct().ToList();
foreach (var distinctType in distinctTypes)
{
model.TypeCount = myExistingDataModel.Count(x => x.Type == distinctType);
model.TypeName = distinctType;
}
Finally ! I managed to do it !
For any future reference :
Based on G_P's answer, I used a LINQ request to count all of my types : Linq distinct - Count (don't forget to remove the .District() otherwise I won't work !)
Then, I did some debuging to see if I actually return my data, because nothing was showing in the chart. It did return my data and the right number.
The issue for this case was, I use
return Json(types.ToDataSourceResult(request, ModelState));
To return my data to my chart. But ! there is a little thing to know about Chart, they don't work like grids. You have to use a specific setup for showing your data if you use ToDataSourceResult : https://docs.telerik.com/aspnet-mvc/html-helpers/charts/data-binding (See "3) (Optional) Configure a Custom DataSource."), just change the call to your controller, and voilĂ  ! It worked !

Find an specific item in the master list of an split app by using oModel.createKey

I'm using a split app layout for editing and creating new employees. Therefore I do have a button "Add employee". After submitChanges is done, I want to find this new employee in the master list and select it.
I am using an event-bus for the communication between detail-controller and master-controller.
fnAfterSubmitChangesSuccess: function(sChanel, sEvent, oData) {
var oResponseData = oData.__batchResponses[0].__changeResponses[0].data;
var sBindingPath = oModel.createKey("/EmployeeSet", {Begda: oData.Begda, Endda: oData.Endda, Pernr: oData.Pernr}).replace(/:\s*/g, "%3A");
},
Is there a way to find the index of a specific listitem by the using binding-path. Or is there another way to solve this problem, instead of looping over the whole list a do a comparison?
I'm afraid the only way to find the index of a specific listItems by binding-path is to walk through the collection of list items. So, I'm afraid that a very plain and short answer would be "No".
It's quite easy though, code is not that lengthy, and it also shouldn't cost to much performance if you're not talking about humongous lists. You will have to walk through the list of items though. Once you have found the item with a binding to the context path you're looking for, you can select it using setSelectedItem, like so:
var list = this.getView().byId("list");
jQuery.each(list.getList(), function(idx, item) {
if (items.getBindingContext().getPath = sBindingPath) {
list.setSelectedItem(item);
}
});
Note: Do keep in mind that if you're working with OData services and are working with a so-called 'growing list', the entry you're looking for may not necessarily be in the list.
Apologies, wish I could give you a more pleasant answer.

Send data from a external class in Swift. Music App

I have been researching over and over again the way to store data depending of the choice of the users and to show it in a UILabel or wherever in different views.
It would be something like this:
First users choose an instrument
In a second view user choose the style of the melody
And in a third one they all can choose the duration of it.
With that a screen is deployed with three changeable labels depending of the preview options which have been chosen.
a. How we can store the information chosen?
b. How to show the information in the lastVC?
So to do this you can use a Facade pattern. to give you an exemple:
you can create a MusicFacade.swift. All the infirmation that you want to store like instrument , style of melody ... are stores in statique variable:
class MusicFacade {
static var _instrument: String =""
static var _stryleMelody: String = " "
static var _duree : Int = 0
}
then when you want to store the information that the user enter you juste use:
MusicFacade._instrument = "Piano"
in you controller code
To have a look on iOS pattern
Hope it 'll help you

How to localize selectOptions on the visual force page

I am trying to localize selectOptions on the Visual Force page.
Here is the .class code snippet:
List<SelectOption> options = new List<SelectOption>();
List<MyOption__c> dropDownValues = [SELECT Id, Display_Label_Name__c FROM MyOption__c];
for (MyOption__c val : dropDownValues) {
// Display_Label_Name__c field is the label from *.labels that needs to be translated
options.add(new SelectOption(val.Id, val.Display_Label_Name__c));
}
Here is the .page code snippet:
<apex:selectList value="{!myVal}">
<apex:selectOptions value="{!options}"/>
</apex:selectList>
Right now the dropdown displays the Display_Label_Name__c verbose. I am trying to see how I can display the translated version from the .labels file. Is it possible? If not, what's the work around?
Thank you for your responses!
All localisation of page text can be done with Custom Labels.
Enable the translation workbench with the languages you require.
Create labels for all the localisible text on the page.
Replace the page text with the labels.
Add a translation for each label.
Change your profile langauge to test.
But for your case you pull the select option text from a custom object. If the values of the select list are not expected to change frequently, less than once a week or so, then I would change to using custom labels.
Otherwise, you lose the value of Salesforce automatic language selection and have to implement something yourself.
I would recommend extending the custom object MyOption__c to have columns for all the supported languages. You could use an if/else block or dynamic apex to select the select option text.
Sample using Dynamic Apex
string language = ParseForSupportedLangauges(UserInfo.getLanguage()); // includes __c
list<sobject> dropDownValues = Database.query('SELECT Id, '+language+' FROM MyOption__c');
for (sobject val : dropDownValues) {
options.add(new SelectOption(val.get('Id'), val.get(language)));
}
ParseForSupportedLangauges() would be a custom method that checks for supported languages and assigns the default when necessary.
EDIT
Turns out there is a solution: Don't look for something until you need it, right?
Introduced in Spring '12 is the ability dynamicaly select the label to display suing array syntax. Also, the ability to create visualforce components from the controller was added but using the array syntax would be sufficient for your problem. This method would allow you to select the labels you want by using the query results from MyOption__c.
Using a repeat in visualforce to loop over the query results
<apex:repeat value="{!displayResultsValues}" var="labelName">
<apex:outputText value="{!$Label[labelName]}"/>
</apex:repeat>
Here is a good article to show the usage and syntax.

JSF Strategies For Long Lists in SelectOneMenu e.g. TimeZones

I am implementing a way for a user to specify their timezone. Nothing new there. I want to hear what people say is a good strategy for handling cases when users need to select from a list of a couple hundred choices, but might not know the correct value for it in the list right away. I know I can use something like autocomplete, but that only works if people know what they are looking for. Sure countries should be obvious but... lowest common denominator (some people are dumb... like me ;).
There are something over 400 distinct iso timezones (not including things like EST, PST, etc. which I am not including). That is a long list. It can be conveniently divided if we let the user chose the country they are in first in say, another selectonemenu. But there are more than 200 countries. So how to present 200 countries that is easy and efficient to work with?
I have already created and packaged in a jar a number of classes to read from the Olson timezone files (iso3166.tab and zone.tab) and provide arraylists of timezone and and timezonecountries, including prioritizing specified countries to the top of the list. But now I would like to maybe learn a better way to present the countries and the timezones. I did this myself since I found it an easier and cleaner way to extract and correlate country codes and timezone codes.
For your particular requirement, I can think of using a world map like you see in a Linux distro like Ubuntu centered at Greenwich. Then placing markers for the data that you have and letting the user select the nearest marker.
See Timezone selection for Ubuntu
For this you can make use the Primefaces GMAP component and add an overlay like this:
LatLng coord1 = new LatLng(36.885233, 30.702323);
PlaceResult placeResultObj1 = new new PlaceResult("660")
//Basic marker
simpleModel.addOverlay(new Marker(coord1, "Konyaalti", placeResultObj1));
PlaceResult.java
public class PlaceResult {
private String utc_offset;
public PlaceResult(String utc_offset){
this.utc_offset = utc_offset;
}
public String getUtc_offset() {
return utc_offset;
}
public void setUtc_offset(String utc_offset) {
this.utc_offset = utc_offset;
}
}
Another approach is to use the Places library from Google maps. Using that you can get the google.maps.places.PlaceResult object by various methods, I like the autocomplete feature where you can choose the city. After a city is selected you can show the utc_offset in the infowindow.
You can take a look at this demo
Currently, it seems that most of the cities don't have utc_offset already set. One of the address I found that had utc_offset was
Newy Airport Transport Shuttle in Australia. Then you can pass the off_set as a input hidden parameter to submit the value to the server.
See also:
Google Places Library

Resources