I'm populating items to a comboBox from an xml file. I'm trying to customize the font-color of each item that appears in the comboBox. Any suggestions?
Thanks!
--Moe
The process is simple if you are using Flash Builder. Each item in your ComboBox is made of an ItemRenderer. Create a custom item render (file - > new -> mxml component) extending that basic ItemRenderer class then assign this new ItemRenderer to your ComboBox. Now inside your custom ItemRenderer you can change values, font sizes, etc ...
You will need to use an ItemRenderer. Though you have not mentioned but it seems you are using Flex 3. The way of using ItemRenderer is slightly different in Flex 3 vs Flex 4. So here is the version for Flex 3:
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600">
<mx:XMLList id="statesXMLList" xmlns="">
<state abbrev="AK" name="Alaska" />
<state abbrev="AZ" name="Arizona" />
<state abbrev="AR" name="Arkansas" />
<state abbrev="CA" name="California" />
<state abbrev="CO" name="Colorado" />
<state abbrev="CT" name="Connecticut" />
</mx:XMLList>
<mx:ComboBox id="comboBox"
prompt="Please select a State..."
dataProvider="{statesXMLList}"
rowCount="3"
labelField="#name"
itemRenderer="ComboBoxItemRenderer"
/>
</mx:Application>
The class for ItemRenderer is ComboBoxItemRenderer which is shown below:
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
<![CDATA[
override public function set data(value:Object):void
{
super.data = value;
lbl.text = value.#name;
if(value.#abbrev == "AK") {
lbl.setStyle("color","#FF0000");
}
else if(value.#abbrev == "AR") {
lbl.setStyle("color","#FF00FF");
}
else {
lbl.setStyle("color","#000000");
}
}
]]>
</mx:Script>
<mx:Label id="lbl"/>
</mx:VBox>
Do not forget the last if (default case) whenever you override set data method.
Related
This is code of watermarktextbox.
<xctk:WatermarkTextBox Watermark="Enter First Name" />
How would I measure the height of that object?
It is simple as this :
Assign a name to your component and measure its height using Height property in code behind.
XAML :
<xctk:WatermarkTextBox x:Name="WatermarkTextBox1" Watermark="Enter First Name" />
Codebehind :
var height = WatermarkTextBox1.Height;
EDIT :
Please use this to get font height. Source : https://stackoverflow.com/a/9251215/5621607
private int GetTextHeight(TextBox tBox)
{
return TextRenderer.MeasureText(tBox.Text, tBox.Font, tBox.ClientSize,
TextFormatFlags.WordBreak | TextFormatFlags.TextBoxControl).Height;
}
I am using Vaadin 7.6.4 for my UI work. This has the following:-
I have a window which contains a grid with data in it. This window is actually a kind of a pop up[ which shows up when my main screen gets a click on the settings icon( not shown here). This is working fine( getting the UI screen to open the Vaadin window when the settings icon the main screen is clicked).
The problem is in showing the data as mentioned below.
This grid will have 4 columns for which the data comes from a bean container.
The first column is a boolean field with true/false getting displayed based on the data from the bean container.
I need to convert this boolean field column into a checkbox with true showing the field as a checkbox with a value selected. If the value is false, then show a checkbox which is not selected.
I am trying to do that as shown in the code below but I keep getting this checkbox name printed. I dont see the checkbox but the word "checkbox" printed in there?
This checkbox should be editable. The idea is that the user should be able to select some checkboxes and the ones selected should be shown in a panel ( not shown here). Thus, the checkbox has to be editable.
How do I fix this? The code for the window is shown below
package com.platform28.mybatis;
import java.util.List;
import com.vaadin.data.Item;
import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.data.util.GeneratedPropertyContainer;
import com.vaadin.data.util.PropertyValueGenerator;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.Grid;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;
#SuppressWarnings("serial")
public class ConfigPopUp extends Window {
VaadinUtils vaadinUtils = null;
public ConfigPopUp(List<TableColumnData> tblDataLst) {
vaadinUtils = new VaadinUtils();
// Some basic content for the window
VerticalLayout configLayout = new VerticalLayout();
configLayout.addComponent(new Label("Settings"));
configLayout.setMargin(true);
//configLayout.setWidth(null);;
setContent(configLayout);
//adding grid.
List<SettingsColumnData> settingsList = vaadinUtils.processSettingsList(tblDataLst);
final BeanItemContainer<SettingsColumnData> gridDataSource = new BeanItemContainer<SettingsColumnData>(SettingsColumnData.class, settingsList);
//change boolean value to checkbox.
GeneratedPropertyContainer gp = new GeneratedPropertyContainer(gridDataSource);
gp.addGeneratedProperty("columnDisplayed", new PropertyValueGenerator<CheckBox>() {
#Override
public CheckBox getValue(Item item, Object itemId, Object propertyId) {
boolean currentCheckBoxValue = (boolean) item.getItemProperty("columnDisplayed").getValue();
CheckBox chkBox = new CheckBox();
chkBox.setValue(currentCheckBoxValue);
return chkBox;
}
#Override
public Class<CheckBox> getType() {
return CheckBox.class;
}
});
Grid settingsGrid = new Grid(gp);
settingsGrid.setWidth("100%");
settingsGrid.setSizeFull();
settingsGrid.setColumnOrder("columnDisplayed", "columnName","columnShortName","columnDescription");
configLayout.addComponent(settingsGrid);
//configLayout.setExpandRatio(settingsGrid, 1);
// Disable the close button
setClosable(false);
HorizontalLayout hLayout = new HorizontalLayout();
hLayout.setSpacing(true);
hLayout.setMargin(true);
// Trivial logic for closing the sub-window
Button ok = new Button("Ok");
ok.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
close(); // Close the sub-window
}
});
hLayout.addComponent(ok);
// Trivial logic for closing the sub-window
Button cancelBtn = new Button("Cancel");
cancelBtn.addClickListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
close(); // Close the sub-window
}
});
hLayout.addComponent(cancelBtn);
configLayout.addComponent(hLayout);
// set pop up to center.
center();
// should be resizable
setResizable(true);
// should not be draggable
setDraggable(false);
//set it as modal window
setModal(true);
setWidth("50%");
setHeight("75%");
}
}
Ok, we used the SelectionMode.MULTI to show the selection of rows in there.
https://cdn.vaadin.com/vaadin-core-elements/latest/vaadin-grid/demo/selection.html
Still, I would love to learn more as to how we get the change done as shown in the question above.
Still looking for an answer to that.
Use a Renderer and a Converter, you don't need to use SelectionMode.MULTI.
An example of this is posted here.
I have created a function that would be able to place the array contents into a listview, Here is my progress so far.
<div id="MainPage" data-role="page" >
<div data-role="content">
RENAME
</div>
</div>
<div id="ViewPage" data-role="page" >
<div data-role="content">
<ul id="viewlist" data-role="listview" data-filter="true" data-filter-placeholder="Sample Contents" data-inset="true">
<!-- array contents goes here -->
</ul>
</div>
</div>
<script>
var sampleContent = new Array( );
displayArray( )
{
for(var scan=0; scan<sampleContent.length; detect++)
{
$('#viewlist').append('<li>' + sampleContent[scan] + '</li>');
}
}
</script>
My code works during the first press of the button but when i pressed it the second time, the list view becomes messed up.
Any help or advice will be glady accepted thanks in advance.
edited, i have figured out how to do it but I am having problems during the second press of the button.
First of i don't want to be rude but i think you should start first to read some basics about android.
Like:
Android Activities , life cycle of activities
Layout in Android (how to add button on an activity then respond to a click etc) , different existing Layout in android and android widget (like the listView for example)
of course there are a lot more to read but it s a good way to start.
However i will provide you codes that will do what you are asking for and i will try to explain as much as i can
First of all you need to create the other activity and inside the layout of that activity insert a listview
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/listView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
then the java code of the other activity will look like this
public class MainActivity2 extends Activity {
//create the array adapter that will input your array and convert it into a list of view
ArrayAdapter<String> arrayAdapter;
String[] list;
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
listView = (ListView)findViewById(R.id.listView);
// get the array from ressource and insert them on an array
list = getResources().getStringArray(R.array.listArray);
// then create the arrayadpater with input your array of string if you dont get //anything here just read android documentation about arrayAdapter
arrayAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list );
//then set the adapter to your listView
listView.setAdapter(arrayAdapter);
}
}
res xml file
<resources>
<string-array name="listArray">
<item>Apple</item>
<item>Banana</item>
<item>Cherry</item>
<item>Cranberry</item>
<item>Grape</item>
<item>Grape</item>
</string-array>
</resources
>
Hope it will help
Just add .listview('refresh') after you have added all items.
$('#viewlist').listview('refresh');
If you want to empty the list each time and refill it, call .empty() before the for loop:
$('#viewlist').empty();
To use better jquery mobile coding, structure your code like this:
Take the onclick out of the anchor tag and add an id:
<a id="viewPageBtn" href="#ViewPage" data-role="button" >RENAME</a>
In your script tag, handle pagecreate on the main page, and within it handle the click event of the anchor:
$(document).on("pagecreate", "#MainPage", function(){
var sampleContent = ["item 1", "item 2", "item 3"];
$("#viewPageBtn").on("click", function(){
$('#viewlist').empty();
for(var scan=0; scan < sampleContent.length; scan++)
{
$('#viewlist').append('<li>' + sampleContent[scan] + '</li>').listview('refresh');
}
$('#viewlist').listview('refresh');
});
});
Im trying to use a checkbox in actionbar,im using actionbarsherlock.
i've tried very hard to get the checkbox work,now I've made the UI (bu using the setCustomView method),but I'm stucked at catch the check event of the checkbox,I did some research of some similar questions but get the answer that "checkbox cant be used in actionbar ,it can only be used in submemus or etc", I doubt that and wondered whether there is a way to get it work...
here is my UI:
here is my CustomView xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:gravity="center_vertical" >
<CheckBox
android:id="#+id/action_anoni_check"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center_vertical"
android:checked="false"
android:gravity="center"
android:text="#string/anonymity" />
</LinearLayout>
here is how i added it in my ui:
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(R.layout.write_actionbar_top);
I know this is an old question, but I thought I'd chime in because I couldn't get Craig's solution to work correctly. The "intended" approach to do this is:
getSupportActionBar().setDisplayShowCustomEnabled(true);
getSupportActionBar().setCustomView(R.layout.write_actionbar_top);
CheckBox mCheckbox = (CheckBox) getActionBar().getCustomView().findViewById(R.id.action_anoni_check);
mCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
//DO YOUR on CHECK ACTION IN HERE
}
}
});
You may want to create a class instance variable and inflate your write_actionbar_top view so you have reference to it, then add a onCheckListener to your checkbox:
private CheckBox mCheckbox;
...
...
mCheckbox = getLayoutInflater().inflate(R.layout.write_actionbar_top, null,false);
mCheckbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked){
//DO YOUR on CHECK ACTION IN HERE
}
}
}
ActionBar actionBar = getSupportActionBar();
actionBar.setCustomView(mCheckbox);
This code hasn't been tested but you should get the idea.
There are also some more ways to get the click or check action on your CheckBox view here -> Android: checkbox listener
This flashbuilder 4.6 application displays a single lineSeries on a line chart based on a chosen name from a dropdown list and the lineseries data shows fine. However, the tooltip shows [object Playername_returntype] instead of the dropdown chosen name.
I also want to dynamically assign the same chosen name from the dropdown to the displayName of the lineseries but have been unable to achieve this. Result shows [object Playername_returntype] as in the tooltip.
Any help would be much appreciated.
Thanks.
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:pool_ratings_yr1service="services.pool_ratings_yr1service.*"
xmlns:pool_playerservice="services.pool_playerservice.*"
minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.controls.Alert;
import mx.events.FlexEvent;
protected function linechart1_creationCompleteHandler(event:FlexEvent):void
{
getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1('Greenleaf');
}
protected function dropDownList_creationCompleteHandler(event:FlexEvent):void
{
getAllpool_playerResult.token = pool_playerService.getAllpool_player();
}
private function comboBoxChange():void
{
var selectedName:String = dropDownList.selectedItem.lname;
getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1(selectedName);
}
]]>
</fx:Script>
<fx:Declarations>
<s:CallResponder id="getpool_ratings_yr1Result"/>
<pool_ratings_yr1service:Pool_ratings_yr1Service id="pool_ratings_yr1Service"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<s:CallResponder id="getAllpool_ratings_yr1Result"/>
<s:CallResponder id="getAllpool_playerResult"/>
<pool_playerservice:Pool_playerService id="pool_playerService"
fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)"
showBusyCursor="true"/>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:LineChart id="linechart1" x="151" y="88" width="800"
creationComplete="linechart1_creationCompleteHandler(event)"
dataProvider="{getpool_ratings_yr1Result.lastResult}" showDataTips="true">
<mx:verticalAxis>
<mx:LinearAxis id="v1" minimum="2000" maximum="2500" title="Average Elo Rating" />
</mx:verticalAxis>
<mx:series>
<mx:LineSeries id="lineSeries" displayName="{dropDownList.selectedItem}" yField="avg_rating"/>
</mx:series>
<mx:horizontalAxis>
<mx:CategoryAxis id="categoryAxis" categoryField="yr"/>
</mx:horizontalAxis>
</mx:LineChart>
<mx:Legend dataProvider="{linechart1}"/>
<s:DropDownList id="dropDownList" x="10" y="88"
creationComplete="dropDownList_creationCompleteHandler(event)"
labelField="lname"
change="comboBoxChange()">
<s:AsyncListView list="{getAllpool_playerResult.lastResult}"/>
</s:DropDownList>
Not entirely sure what you're after, but for the LineSeries displayName, here's what I did:
Created a [Bindable] String variable for each Line Series, and then whenever the data changed, just assign whatever value you want to the variable. In your example:
private function comboBoxChange():void
{
var selectedName:String = dropDownList.selectedItem.lname;
getpool_ratings_yr1Result.token = pool_ratings_yr1Service.getpool_ratings_yr1(selectedName);
// Private Bindable String variable(myString) assigned earlier
myString = selectedName;
}
And then in your mxml:
displayName="{myString}"
Hope that's clear enough!