The MonoTouch.Dialog RootElement does not appear to have a way of adding a subtitle. I would like to display a subtitle below the caption.
Do I have to subclass the element and add a custom view to in the GetCell method?
Is there a simpler option?
The simplest way to achieve this is to subclass RootElement and override GetCell method, create a new cell and set the LabelText and DetailLabelText. This will give you a nice subtitle
public override MonoTouch.UIKit.UITableViewCell GetCell(MonoTouch.UIKit.UITableView tv) {
var baseCell = base.GetCell(tv);
var cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "cellId");
cell.TextLabel.Text = Caption;
cell.DetailTextLabel.Text = _subtitle;
cell.Accessory = baseCell.Accessory;
return cell;
}
Note the cell Style. Unfortunately, it looks like the cell style is available only during cell construction and not afterward. So you cant just call base.GetCell(tv) and set it's style. That would have been a better option.
_subTitle is a class level variable set via the custom constructor
private string _subtitle = string.Empty;
public ChartSectionRootElement(string caption, string subTitle) : base(caption) {
this._subtitle = subTitle;
}
Related
I am passing List tableitems and then in get cell i am doing this which is generating image view with the last image in each cell.I want all the 4 images in different different cell.the get cell method for this is below:-
public override UICollectionViewCell GetCell (UICollectionView collectionView, NSIndexPath indexPath)
{
UITableView cell = TableViewView.DequeueReusableCell (CardCellId) as UITableViewCell;
foreach(UIImage img in tableitems)
{
cell.ImageView.Image=img;
}
return cell;
}
here tableitems is my list of UIImages.
You're looping through your array every time GetCell is called which is why only the last image is assigned to your imageView.
Try doing cell.imageView.image = tableitems[indexPath.row] assuming tableitems is [UIImage]()
I have HeaderUsesThemes to false. When I 'edit columns' I can set the forecolor property of each header just fine but there is no property for the back color.
How can I set the back color of the Headers?
with ObjectListView, you can change the back color of Headers using the HeaderFormatStyle class.
Here is a short example (change all headers to the same style using DarkBlue as Backcolor and Gray for text):
using System;
//...
using BrightIdeasSoftware;
//...
private void adjustMyObjectListViewHeader()
{
foreach (OLVColumn item in olv.Columns)
{
var headerstyle = new HeaderFormatStyle();
headerstyle.SetBackColor(Color.DarkBlue);
headerstyle.SetForeColor(Color.SlateGray);
item.HeaderFormatStyle = headerstyle;
}
}
olv is the ObjectListView Object
Details can be found in the ObjectListView Cookbook:
http://objectlistview.sourceforge.net/cs/recipes.html#how-do-i-change-the-font-or-color-of-the-column-headers
Hope this helps...
I am trying to finish up a custom cell for my tables using monotouch.dialog, and have nearly everything sorted out, except for my cell's detail text label colour.
I am overriding GetCell to customise my EntryElement cell like this:
public class CustomStyledEntryElementPlain : MonoTouch.Dialog.EntryElement
{
public CustomStyledEntryElementPlain (string _caption, string _value) : base(string.Empty,string.Empty,string.Empty,false)
{
KeyboardType = UIKeyboardType.Default;
Value = _value;
ReturnKeyType = UIReturnKeyType.Done;
Caption = _caption;
}
public override UITableViewCell GetCell(UITableView tableView) {
var cell = base.GetCell(tableView);
cell.BackgroundColor = Resources.XDarkGrayColor;
cell.TextLabel.TextColor = Resources.XWhiteColor;
cell.BackgroundView = new UIView (RectangleF.Empty);
cell.DetailTextLabel.TextColor = UIColor.White; //this line causes the error
return cell;
}
}
I then create the elements like so:
new CustomSection ("Testing"){
new CustomStyledEntryElementPlain("Test","Test1"),
new CustomStyledEntryElementPlain("Test","Test2")
},
However, on displaying the table, I get the error: "System.NullReferenceException has been thrown Object reference not set to an instance of an object"
I could have sworn when I initially prototyped this that I had the DetailTextLabel text color working! Commenting out the change of course results in my table and cell displaying just fine, albeit with black text (which I want to change to white!)
Has anyone got any idea as to why I am getting this?
The DetailTextLabel property in the UITableViewCell is only available if the Cell has a UITableViewCellStyle that supports it. From the UITableViewCell documentation for the DetailTextLabel property:
UITableViewCell automatically creates the secondary (detail) label if the cell is created with a MonoTouch.UIKit.UITableViewCellStyle that supports a detail label.
If the cell's style doesn't support a detail label, this property returns null.
Check the documentation for UITableViewCellStyle to find out which styles support this property.
I'm developing an app on android and I am generating UI elements in a loop. But I need these elements to have an id with letters and numbers, for example "rl1" or "rl2". I was trying to use the method RelativeLayout.setId() but, that method only accepts int. Is there a way I can set an ID as I want without being limited to numbers?
Thanks.
Here is the code I am trying to make work.
for (int i=1; i < 10; i++)
{
//gets the frameview where the elements will be created.
String LinearLayoutId = "frameview1";
int resID = getResources().getIdentifier(LinearLayoutId, "id", "com.myapp.ERS");
LinearLayout linearLayout = (LinearLayout)findViewById(resID);
//creates the RelativeLayout that will hold the ImageIcon and the TextView
RelativeLayout rl = new RelativeLayout(this);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,40 );
rl.setLayoutParams(lp);
rl.setId("rl"); /// >>>> I would like here to set and ID of "rl1" for example.
rl.setBackgroundDrawable(getResources().getDrawable(R.drawable.bk36));
//creates the image icon within the layout at the left side
ImageView image = new ImageView(this);
lp = new RelativeLayout.LayoutParams(
40,RelativeLayout.LayoutParams.MATCH_PARENT );
image.setLayoutParams(lp);
String imageicon = "icon_"+i;
resID = getResources().getIdentifier(imageicon, "drawable", "com.myapp.ERS");
image.setImageDrawable(getResources().getDrawable(resID)); //sets the icon
rl.addView(image); //adds the ImageView to the relative layout
//creates the TextView within the layout with a 40 margin to the left
TextView tv = new TextView(this);
lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT );
lp.setMargins(40, 0, 0, 0);
tv.setLayoutParams(lp);
String textViewID = "tv"+i;
resID = getResources().getIdentifier(textViewID, "string", "com.myapp.ERS");
tv.setText(getResources().getString(resID));
tv.setTextColor(Color.BLACK);
tv.setTextSize(25);
rl.addView(tv);//adds the TextView to the relative layout
rl.setOnClickListener(mAddListener);
linearLayout.addView(rl);//adds the RelativeLayout to the LinearLayout
}
and then I have the OnCLickListener like this...
private OnClickListener mAddListener = new OnClickListener()
{
public void onClick(View v){
Intent intent;
Bundle bundle;
String id = getResources().getResourceEntryName(v.getId());
id = id.replaceAll("\\D+","");
int value = Integer.parseInt(id);
intent = new Intent(ERS.this, ShowInfo.class);
bundle = new Bundle();
bundle.putInt("key", value);
System.out.println(v.getId());
intent.putExtras(bundle);
startActivity(intent);
}
};
I have tried to set up numeric IDs, but then when I Look for them with:
String id = getResources().getResourceEntryName(v.getId());
It can't find them.
I had all of this in an xml file to begin with, but it was really long because there are about forty items in the list, and it was complicated for me to go and change a letter for example in all of them. I came up with this idea to generate them at runtime in a for loop. I am testing in the meantime with ten, but I can't get it to work.
If I am doing something incorrect, then pardon me, but I am new to this.
You may still find it easier to go back to XML layouts and use the R class to generate meaningful IDs. Although as you haven't included the original xml file you refer to at the end of the question, so I can only guess at the problem you had with it. It does seem to fit the bill though, and would allow you to create something along the lines of:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/hellotextview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hi there"/>
The android:id="#+id/hellotextview" generates an id that can be used elsewhere in your project. In your java code you could access that specific TextView with something similar to:
TextView helloText = (TextView) findViewById(R.id.hellotextview);
The R.id.hellotextview is a int automatically generated when the project is built (in gen/R.java), but as you get to pick the name you can assign them something relevant to you and your project. So instead of trying to use strings values such as "rl1" and "rl2" that you mentioned, you could use R.id.rl1 and R.id.rl2.
As well as individual UI elements, you can also use the same technique for strings (in res/values/strings.xml), and other resources stored under the project's res/ folder, such as icons, media files, etc. In the case of strings you would access them getString(R.string.some_name_given_by_you);
See Accessing Resources at the Android Developers site for more info.
Why dont you try using SharedPreferences as an alternative in case you want to access the elements which you give some ID elsewhere in some other activity.
Consider something like this:
new RootElement ("Root"){
new Section ("Section A") {
new EntryElement("Element in A")
}
new Section ("Section B") {
new EntryElement("Element in B")
}
}
and Monotouch.Dialog will create you TableView with two sections. Now I want the second section to be located not right under the first section but rather at very bottom of the screen. How can I do that?
It seems you can trick Monotouch.Dialog by defining empty HeaderView for the section. It will expand the space between sections. Something like this:
lastSection.HeaderView = new UIView(new RectangleF(0,0,0,80));
I'm not sure though this is the right approach. Worked for me.
I do not believe MonoTouch.Dialog can do this of the box. You will need to:
Define a large transparent UITableViewCell subclass.
Define an ‘Element’ subclass and override it’s GetCell(...) method to provide the cell you subclassed above.
Implement IElementSizing on the element above and implement GetHeight(...) to describe the height of the transparent cell between the first and last cells.
Create an empty Section with the Element subclass between your top EntryElement and the bottom EntryElement section.
The resulting code would look something like this:
this.Root = new RootElement ("Root") {
new Section ("Section A") {
new EntryElement("Element in A")
}
new Section("") {
new EmptyElement()
}
new Section ("Section B") {
new EntryElement("Element in B")
}
};