I am new to ANDROID DEVELOPMENT. I learnt java before jumping in to Android. I see this code in a book and I am stumped.  How does this even work?  I get the part that the setbutton method of progressDialog class is receiving parameters.  But the 3rd parameter is a class? I though new keyword is used to create a new type (a class). how is that a method (.OnClickListener) is being referenced when the class is being created on top of all, there is another method(onClick) being created inside it. Obviously, there is something in java I am not aware of. Can someone tell me if there is a tutorial on this concept in java? I am not worried about a button being created and being clicked on. I am talking about the concept of this programming used in here.   Thank you so much.  progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, “OK”,     new DialogInterface.OnClickListener() {         public void onClick(DialogInterface dialog,int whichButton)         {             Toast.makeText(getBaseContext(),“OK clicked!”,                  Toast.LENGTH_SHORT).show();         } });
What is the use of anonymous classes in Java? Can we say that usage of anonymous class is one of the advantages of Java?
What's the easiest way to figure out if a window is opened modally or not?  CLARIFICATION:  I open a window calling   myWindow.ShowDialog();   I have a footer with an "OK" &amp; "Cancel" button that I only want to show if the window is opened modally. Now I realize I can set a property by doing this:  myWindow.IsModal = true; myWindow.ShowDialog();   But I want the window itself to make that determination. I want to check in the Loaded event of the window whether or not it is modal.  UPDATE  The IsModal property doesn't actually exist in a WPF window. It's a property that I have created. ShowDialog() blocks the current thread.   I'm guessing I can determine if the Window is opened via ShowDialog() by checking if the current thread is blocked. How would I go about doing that? CASESAFEID() apex equivalent Is there any function in Apex which could emulate functionality of the  formula function? I'm trying to get 18-char Id variant from the standard one. Is this a valid partial fraction decomposition? Write $\dfrac{4x+1}{x^2 - x - 2}$ using partial fractions. $$ \frac{4x+1}{x^2 - x - 2} = \frac{4x+1}{(x+1)(x+2)} = \frac{A}{x+1} + \frac{B}{x-2} = \frac{A(x-2)+B(x+1)}{(x+1)(x-2)}$$ $$4x+1 = A(x-2)+B(x+1)$$ $$x=2 \Rightarrow 4 \cdot2 + 1 = A(0) + B(3) \Rightarrow B = 3$$ $$x = -1 \Rightarrow 4(-1) +1 = A(-3)+ B(0) \Rightarrow A = 1$$ Thus, $$\frac{4x+1}{x^2-x-2} = \frac{1}{x+1} + \frac{3}{x-2}\textrm{.}$$  The substitution of $x$ ($x = 2, -1$) is a common method to find out the coefficient of the partial fractions. However, the equation on the third line is obtained by multiplying $(x+1)(x-2)$, which is assumed to be nonzero. Here we have a contradiction. Furthermore, the original function is not defined at $x=-1,2$. How can we substitute these value for $x$? So is this method valid and rigorous? How to modify it so that it is rigorous? Multiple Inheritance in C# Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. For instance I'm able to implement the missing multiple inheritance pattern using interfaces and three classes like that: public interface IFirst { void FirstMethod(); } public interface ISecond { void SecondMethod(); }  public class First:IFirst  {      public void FirstMethod() { Console.WriteLine(&quot;First&quot;); }  }  public class Second:ISecond  {      public void SecondMethod() { Console.WriteLine(&quot;Second&quot;); }  }  public class FirstAndSecond: IFirst, ISecond {     First first = new First();     Second second = new Second();     public void FirstMethod() { first.FirstMethod(); }     public void SecondMethod() { second.SecondMethod(); } }  Every time I add a method to one of the interfaces I need to change the class FirstAndSecond as well. Is there a way to inject multiple existing classes into one new class like it is possible in C++? Maybe there is a solution using some kind of code generation? Or it may look like this (imaginary c# syntax): public class FirstAndSecond: IFirst from First, ISecond from Second { }  So that there won't be a need to update the class FirstAndSecond when I modify one of the interfaces.  EDIT Maybe it would be better to consider a practical example: You have an existing class (e.g. a text based TCP client based on ITextTcpClient) which you do already use at different locations inside your project.  Now you feel the need to create a component of your class to be easy accessible for windows forms developers. As far as I know you currently have two ways to do this:  Write a new class that is inherited from components and implements the interface of the TextTcpClient class using an instance of the class itself as shown with FirstAndSecond.  Write a new class that inherits from TextTcpClient and somehow implements IComponent (haven't actually tried this yet).   In both cases you need to do work per method and not per class. Since you know that we will need all the methods of TextTcpClient and Component it would be the easiest solution to just combine those two into one class. To avoid conflicts this may be done by code generation where the result could be altered afterwards but typing this by hand is a pure pain in the ass. Total order on complex numbers Can I change a user's keyboard input? How to ensure OpenVPN connection uses specific DNS? I'm using OpenVPN through Tunnelblick on MacOS X Lion.  I need to set specific DNS (with local IP, which works only when VPN is up) for the duration of this VPN session only.  I do not have access to the OpenVPN server configuration. Only client config. Also, DNS from the server doesn't work.  So it works like this: I connect to VPN, go the Network preferences and manually set DNS. After VPN is disconnected, I switch back to default. It works, but it needs to be automatic.  After some exploration I found that OpenVPN up- and down- scripts might help me with that. Unfortunately, I haven't found any specific documentation about how exactly it can be done.  How it can or can't be done? Any advice would be appreciated! At this point, I am unclear as to how to handle encounter XP. Does each surviving party member receive a proportional share, or the full amount? That is, assume a 4-character party had completed an encounter worth 400 XP. Would each party member receive 100 XP, or 400 XP? What do you call a person who is utterly independent and a loner? Split a file by line and have control over resulting files extension How do I turn on workspaces? (Why do I only have one workspace?) It appears that Unity on Raring only comes with a single virtual desktop (aka workspaces) by default, and CCSM's Wall plugin has no way to add more. Is this configurable at all? How to send text to Notepad in C#/Win32? I'm trying to use SendMessage to Notepad, so that I can insert written text without making Notepad the active window.  I have done something like this in the past using SendText, but that required giving Notepad focus.  Now, first I'm retrieving the Windows handle:  Process[] processes = Process.GetProcessesByName("notepad"); Console.WriteLine(processes[0].MainWindowHandle.ToString());   I've confirmed it's the right handle for Notepad, the same shown within Windows Task Manager.  [DllImport("User32.dll", EntryPoint = "SendMessage")] public static extern int SendMessage(int hWnd, int Msg, int wParam, int lParam);   From here, I haven't been able to get SendMessage to work in all my experimentation.  Am I going in the wrong direction? Can we use curved spacetime to measure the one-way speed of light? This is related to  and  The idea is to shine a beam of light from a clock towards a heavy mass, like a black hole, in some manner such that the curvature of spacetime around the mass is sufficient to &quot;bend&quot; the light directly back to the clock. That is, to send the light along a self-intersecting geodesic using a sufficiently curved spacetime. Note that in this case the source and the detector are the same object, so no clock synchronization is required. Hypothetically, this should measure the one-way speed of light. None of the given refutations from the similar posts on this site are convincing. Here are some of the main refutations, as I understand them, and my counter to them: (1) In being curved by spacetime, the light is actually changing direction, hence this is not the one-way speed. To my understanding of General Relativity, the light travels along a geodesic; that is, a curve such that, ignoring technicalities of Differential Geometry, its tangent direction is constant. There is no reflection or acceleration. So in this sense, how can the light with a constant tangent direction be said to change direction? One might say that the path deviates from a straight line in Euclidean space, but given that spacetime is not Euclidean, has no , and has no global notion of direction, this is the only definition of straight or &quot;one direction&quot; that makes sense. Thus, either the light does not change direction and is &quot;one-way,&quot; or we need to be clearer about what exactly we mean by &quot;one-way&quot; in the context of General Relativity. (2) Such an experiment would be impossible or impractical. I think some posters were saying this because the original questions implied that the clock would have to be at the event horizon of a black hole, which is of course impossible or impractical; however, I don't think such an extreme closeness to the black hole is required. Given that the  of a black hole, where light orbits in a circle, is outside of the event horizon, shining the light at some distance outside of the photon sphere should be sufficient to curve the light back to the clock, regardless of the distance of the clock from the black hole (see my rough illustration). At the extreme, we could place the clock directly on the photon sphere, which should be theoretically possible. Regardless, the question is not about practicality, but whether the one-way speed is theoretically measurable.  Update: Essentially what this argument boils down to, I think, is that the average speed of light along a single self-intersecting geodesic may differ from the average speed of light along a non-geodesic self-intersecting path, which is always c. Put that way, however, it does seem a little ridiculous. It is hard to see how the anisotropy of the speed could be defined in such a way as to be consistent with this pathological case. Presumably, we could approximate a single self-intersecting geodesic with a non-geodesic path arbitrarily closely, so, logically, the average speeds over each path should be approximately the same, i.e., c. Furthermore, how would the &quot;preferred direction&quot; of the speed of light behave around a black hole, for instance? Regardless, I still think this experiment does actually solve the problem for the given notion of &quot;direction&quot;. Though the problem is usually posed in the flat spacetime of Special Relativity, with a global notion of direction, so the apparent unanswerability of this question should be seen as a limitation of Special Relativity only, which is then solved by General Relativity. What are my best options for a tripod for up to $100? I'm looking to buy a tripod + head (for my Canon 40D), but am not sure if I want to spend more than $100 on it.  So can you suggest options for best tripods for $100 or less? Or, is it important to spend more than that on a tripod?  Extra props for options which might be available in India. Show that $2^n > n^2$ whenever n>4. Let $S(n)$ be the proposition "$2^n &gt; n^2$"  Basis step: $S(5)$ is true, since $2^5 = 32$, $ 32 &gt; 25 = 5^ 2$  Inductive step:  Induction hypothesis:   Assume $S(K)$ is true, $2^K &gt; K^2$.  Then  $2^{K+1} = 2.2^K &gt; K^2 + K^2$   I don't know how to proceed after this. How to complete this proof? Unable to Enter a Country If I have a connecting flight through a country I am unable to enter. Can I retrieve my bags to recheck for my connect? How is the Gmail password stored in Android - and where? I have looked around and found no information on how Android manages to store passwords on the device. Especially Gmail passwords. I'm looking to learn how Android encrypts and stores passwords ? What key does it use and where is this key stored, and what encryption algorithm it uses. Shouldn't this table span the whole page width? I have this table definition as part of a invoice  \begin{tabularx}{\textwidth}[ht]{lXrr}%   It worked fine for years until I have a very short word in the X column for the first time. Now my table is very small in width and centered horizontally on the page.  In my expectation the X column should fill up all space until the width of the table reaches the width of the page except the margins.  I have read about workarounds specifying something like 1.2\textwidth, but I don't like that, because the table is a template included via \include, so it would affect all my invoices.  I also tried \linewidth, \hsize and \columnwidth, but everything results in the same layout.  Is there a way to make the only X column expand so that it uses all available space?    Complete included table definition (Rechnungstabelle.tex):  \newcommand{\Rechnungstabelle}[4]{% vielen Dank für Ihren Auftrag. \noindent \begin{tabularx}{\textwidth}[ht]{lXrr}% \toprule% \bf{Anzahl} &amp; \bf{Bezeichnung} &amp; \bf{Einzelpreis} &amp; \bf{Gesamtpreis} \\% \midrule% #1% \bottomrule% &amp; \bf{Rechnungsbetrag}  &amp; &amp; \bf{\EUR{#2}} \\% \ifthenelse{\equal{#3}{}}{}{&amp; Enthaltene MwSt. 19\% &amp; &amp; \EUR{#3} \\}% \ifthenelse{\equal{#4}{}}{}{&amp; * Enthaltene MwSt. 7\% &amp; &amp; \EUR{#4} \\}% \end{tabularx}% }   Changing the table header row to  \bf{Anzahl} &amp; \bf{Bezeichnung} \hspace{\textwidth} &amp; \bf{Einzelpreis} &amp; \bf{Gesamtpreis} \\%   is a workaround, but I don't think that would be good TeX style.  Minimum example for reproducing:  \documentclass[ fontsize=12pt,                  paper=a4,                 foldmarks=TBMPL,                 fromalign=center,                 ngerman                 ]{scrlttr2} \usepackage{babel} \usepackage[utf8]{inputenx} \usepackage[right]{eurosym} \usepackage{tabularx} \usepackage{ltablex} \usepackage{booktabs} \usepackage{ifthen}  \input{Rechnungstabelle} \begin{document} \begin{letter}  \Rechnungstabelle{     1,0 h &amp; Do something &amp; \EUR{99,00} &amp; \EUR{99,00} \\      }     {99,00}     {}{} \end{letter} \end{document} How to Fix:Though favicons are added, it doesn't show in Google Search Why can't we initialize members inside a structure?