Thursday 3 October 2013

How to set ActionMode LayoutParams to make custom view match_parent?

How to set ActionMode LayoutParams to make custom view match_parent?

I'm trying to set a custom view into an ActionMode, but it doesn't match
ActionMode as parent. In comparison with the standard ActionBar, when you
are setting a custom view you can specifiy layout params, while is not
provided in ActionMode.
There´s any solution?
mode.setCustomView(mModeActionBarView);
getSupportActionBar().setCustomView(customActionBarView, new
ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
Thanks a lot!

Wednesday 2 October 2013

Java super constructor execution sequence

Java super constructor execution sequence

I've been studying from the Java Certification Bates and Sierra book and
am stumped on chapter 2 constructor explanation:
public class Animal {
String name;
Animal(String name) {
super();
{System.out.println("Hello");} //I put this in myself
this.name = name;
}
Animal() {
this(makeRandomName());
}
static String makeRandomName() {
int x = (int) (Math.random() * 5);
String name = new String[] {"Fluffy", "Fido",
"Rover", "Spike",
"Gigi"}[x];
return name;
}
public static void main (String [] args) {
Animal a = new Animal();
System.out.println(a.name);
Animal b = new Animal("Zeus");
System.out.println(b.name);
}
}
The following is from the Bates and Sierra book:
"Notice that the makeRandomName() method is marked static! That's because
you cannot invoke an instance (in other words, nonstatic) method (or
access an instance variable) until after the super constructor has run.
And since the super constructor will be invoked from the constructor on
line 3, rather than from the one on line 7, line 8 can use only a static
method to generate the name."
I did an experiment and I inserted a super call in the overloaded
constructor and my results were:
Hello Rover Hello Zeus
Now from these results, it seems as though the overloaded constructor AND
the super constructor is executed before the static method because Hello
prints before Zeus and Rover. So, why is there a need for a static
variables?
What am I missing?
Thanks, Jane

How can I reuse a Dropdownlist in several views witn .NET MVC

How can I reuse a Dropdownlist in several views witn .NET MVC

Several views from my project have the same dropdownlist...
So, in the ViewModel from that view I have :
public IEnumerable<SelectListItem> FooDdl { get; set; }
And in the controller I have :
var MyVM = new MyVM() {
FooDdl = fooRepository.GetAll().ToSelectList(x => x.Id, x => x.Name)
}
So far so good... But I´m doing the same code in every view/controller
that have that ddl...
Is that the best way to do that?
Thanks

How to wire-up UISegmentedControl from a prototype cell?

How to wire-up UISegmentedControl from a prototype cell?

I have a UISegmentedControl defined in my storyboard within a prototype
cell. Trying to plug the control into an IBOutlet results in the Xcode
error "Couldn't compile connection". After some searching, I found this
error message is because IBOutlet can't be used with a prototype cell in
this way. Is there a way to access the UISegmentedControl* through the id
parameter of an IBAction wired up to the control?

vb.net back to back, identical lines: 1 works, 1 doesn't

vb.net back to back, identical lines: 1 works, 1 doesn't

I have these 2 lines of code:
MsgBox(tr.InnerText.Contains("Completed"))
MsgBox(tr.InnerText.Contains("removed"))
They appear right after eachother, in that order (tr is an htmlelement
defined earlier). The first line executes no problem, the second line
returns an object reference not set. What gives gais?

Tuesday 1 October 2013

Template function default parameter and type inference

Template function default parameter and type inference

C++
None of these template functions
template<typename T> void foo(T par = nullptr) {return;} //#1
template<typename T> void foo(T par = std::nullptr_t(nullptr)) {return;}
//#2
template<typename T> void foo(T par = int(0)) {return;} //#3
allow anything with the following zero-argument call to compile:
foo();
although calling foo with any value works (e.g. foo(2)).
nullptr has a specific type, which is std::nullptr_t, so I didn't think
the default parameter needed extra type qualification in #1. The type of
the default parameter is explicitly provided in #2 and #3, so I didn't
think there was any type ambiguity there.
What is wrong here? Is there a proper way to do default parameters with
template functions?

Design issue in C++

Design issue in C++

This is rather question on a design issue than a problem on c++. I'll try
to describe my thoughts in an abstract way:
I'm the "owner" of some service object A0, dynamically created by a
framework. To do my job I created dependent aggregated classes A1, A2, A3,
... to handle different specific requests.
Within A1, A2, A3... I typically use resources like a database connection,
a property tree etc..., which are available from the framework, which
calls A.
What is the best way, to make these resources "available" from A1...An ?
Typically I have setter-Methods like
a0->setFramework(myFramework);
a1->setFramework(a0->getFramework());
a2->setFramework(a0->getFramework());
a3->setFramework(a0->getFramework());
Then I use other dependent classes, to complete a specific request, e.g. a
ResponseWriterA for A, which needs also some of the mentioned services.
Therefore, I have to implement a setter
ResponseWriterInstanceA->setFramework(a1->getFramework())
and so on.
Although this works, I don't regard it as a good solution, since the same
set of resources is "propagated" through along the whole set of classes.
Moreover, I typically end up with all my subclasses depending somehow on
the whole framework, which makes it hard, to isolate classes ("each
include File is everywhere afterwards").
I would prefer a more centralized access to the set of resources, without
the need to pass data through and to keep the worker classes independent
of other nasty things. But I dont know, how to do that in a "proper"
way...
On the one hand I dont't want to use static (class) methods, but for all
other approaches, I need an object. How to get this instance, if it is not
passed as a dependent object to all of my worker-instances?
What is the typical "golden way" (maybe some kind of design pattern) to
solve such issues?
Many Thanks !

LAN not working on DELL 3360

LAN not working on DELL 3360

I have a dell Vostro 3360 and i have recently removed windows and
installed Ubuntu 12.04 I am able to use WiFi and Bluetooth but it does not
detect when any LAN cable is connected.
I tried unblocking everything using sudo rfkill unblock all but to no
avail. please help ASAP as i am a college student and i need LAN
connectivity