问:
How to bind a function to click event on an embed
I'm trying to bin a function to click event on an embed (flash file). But the problem is the support, so I'm looking for a cross-browser solution. The first thought was add the onclick attribute to the embed element but in Chrome (v. 59.0.3071.115) the click event is never fired, or the onclick is not working...

Code 1:

```<code><embed onclick='myFunction(myOpts)'
       class="item"
       src="/file.swf">

function myFunction(myOpts){
    console.log('is working!!!!');
}
</code>```

The above code is not working on Chrome. So, I was thinking in a new way to call this function on a click event: a parent div with the onclick attribute and fire the embed click with javascript (to play the Flash), this is the code:

Code 2:

```<code><embed onclick='myFunction(myOpts, event)'
       class="item"
       src="/file.swf">

function myFunction(myOpts, event){
    console.log('is working!!!!');
    event.target.getElementsByTagName('embed')[0].click();
}
</code>```

But the embed's click is never fired... So, my question:

Is there a way to call a function with the a click event on an embed? If the answer is yes, which is the best way to call a function without affecting his behavior?

答:
If you need to get the current element, pass this inside onClick function.

Then you will be able to call element.click() inside myFunction.

```<code>onClick="myFunction('test', this)"

function myFunction(myOpts, element) {

    console.log(element, 'is working!!!!');
    // calling here element.click() will trigger myFunction twice
}
</code>```

Body:
I'm trying to bin a function to click event on an embed (flash file). But the problem is the support, so I'm looking for a cross-browser solution. The first thought was add the onclick attribute to the embed element but in Chrome (v. 59.0.3071.115) the click event is never fired, or the onclick is not working...

Code 1:

<embed onclick='myFunction(myOpts)'
       class="item"
       src="/file.swf">

function myFunction(myOpts){
    console.log('is working!!!!');
}

The above code is not working on Chrome. So, I was thinking in a new way to call this function on a click event: a parent div with the onclick attribute and fire the embed click with javascript (to play the Flash), this is the code:

Code 2:

<embed onclick='myFunction(myOpts, event)'
       class="item"
       src="/file.swf">

function myFunction(myOpts, event){
    console.log('is working!!!!');
    event.target.getElementsByTagName('embed')[0].click();
}

But the embed's click is never fired... So, my question:

Is there a way to call a function with the a click event on an embed? If the answer is yes, which is the best way to call a function without affecting his behavior?

Body:
If you need to get the current element, pass this inside onClick function.

Then you will be able to call element.click() inside myFunction.

onClick="myFunction('test', this)"

function myFunction(myOpts, element) {

    console.log(element, 'is working!!!!');
    // calling here element.click() will trigger myFunction twice
}


来源: stackexchange

问:
Why does a C++ friend class need a forward declaration only in other namespaces?
Suppose I have a class F that should be friend to the classes G (in the global namespace) and C (in namespace A).

to be friend to A::C, F must be forward declared.

to be friend to G, no forward declaration of F is necessary.

likewise, a class A::BF can be friend to A::C without forward declaration

The following code illustrates this and compiles with GCC 4.5, VC++ 10 and at least with one other compiler.

```<code>class G {
    friend class F;
    int g;
};

// without this forward declaration, F can't be friend to A::C
class F;

namespace A {

class C {
    friend class ::F;
    friend class BF;
    int c;
};

class BF {
public:
    BF() { c.c = 2; }
private:
    C c;
};

} // namespace A

class F {
public:
    F() { g.g = 3; c.c = 2; }
private:
    G g;
    A::C c;
};

int main()
{
    F f;
}
</code>```

To me this seems inconsistent. Is there a reason for this or is it just a design decision of the standard?

答: Because it wouldn't make sense to be able to declare something in the global namespace if you're inside a namespace {} block. The reason friend class BF; works is that it acts like an implicit forward declaration.

ContentLicense: CC BY-SA 2.5

Body:
Suppose I have a class F that should be friend to the classes G (in the global namespace) and C (in namespace A).

to be friend to A::C, F must be forward declared.

to be friend to G, no forward declaration of F is necessary.

likewise, a class A::BF can be friend to A::C without forward declaration

The following code illustrates this and compiles with GCC 4.5, VC++ 10 and at least with one other compiler.

class G {
    friend class F;
    int g;
};

// without this forward declaration, F can't be friend to A::C
class F;

namespace A {

class C {
    friend class ::F;
    friend class BF;
    int c;
};

class BF {
public:
    BF() { c.c = 2; }
private:
    C c;
};

} // namespace A

class F {
public:
    F() { g.g = 3; c.c = 2; }
private:
    G g;
    A::C c;
};

int main()
{
    F f;
}

To me this seems inconsistent. Is there a reason for this or is it just a design decision of the standard?


问:
GtkBox implicit margin between children
Is it possible to remove all margins between two widgets inside a GtkBox?

Tried: Set everything to zero

Result: Still 2px effective margin

GTK+ Version: 3.18.9

Widget properties:

Drawing code:

```<code>auto w_out=static_cast<double>( gtk_widget_get_allocated_width(widget) );
auto h_out=static_cast<double>( gtk_widget_get_allocated_height(widget) );

cairo_set_source_rgba(cr,self->m_background.red,self->m_background.green
    ,self->m_background.blue,self->m_background.alpha);
cairo_rectangle(cr,0,0,w_out,h_out);
cairo_fill(cr);

auto img=self->r_img;
if(img!=nullptr)
    {
    //...
    }
</code>```

The actual size is 22 x 22 as expected.

Rendered result:

It appears that this is not a theming issue, since all themes behaves the same.

答:
I've tried on the same Gtk version:

```<code>$ rpm -q gtk3-devel
gtk3-devel-3.18.9-1.fc23.x86_64
</code>```

and it did work without any borders as can be seen:

The images are centered due to horizontal alignment set as center. Resizing the window to the smallest size:

The image used was a crop from the original (22x22 px):

Conclusion

Seems that you are creating a custom widget, maybe there's something you're missing (more details needed). From regular widgets (GtkImages packed on a GtkBox, tested with glade) it seems to work fine.

ContentLicense: CC BY-SA 3.0

Title: GtkBox implicit margin between children

Body:
Is it possible to remove all margins between two widgets inside a GtkBox?

Tried: Set everything to zero

Result: Still 2px effective margin

GTK+ Version: 3.18.9

Widget properties:

Drawing code:

auto w_out=static_cast<double>( gtk_widget_get_allocated_width(widget) );
auto h_out=static_cast<double>( gtk_widget_get_allocated_height(widget) );

cairo_set_source_rgba(cr,self->m_background.red,self->m_background.green
    ,self->m_background.blue,self->m_background.alpha);
cairo_rectangle(cr,0,0,w_out,h_out);
cairo_fill(cr);

auto img=self->r_img;
if(img!=nullptr)
    {
    //...
    }

The actual size is 22 x 22 as expected.

Rendered result:

It appears that this is not a theming issue, since all themes behaves the same.

Body:
I've tried on the same Gtk version:

$ rpm -q gtk3-devel
gtk3-devel-3.18.9-1.fc23.x86_64

and it did work without any borders as can be seen:

The images are centered due to horizontal alignment set as center. Resizing the window to the smallest size:

The image used was a crop from the original (22x22 px):

Conclusion

Seems that you are creating a custom widget, maybe there's something you're missing (more details needed). From regular widgets (GtkImages packed on a GtkBox, tested with glade) it seems to work fine.


问:
How to programmatically set drawableLeft on Android button?
I'm dynamically creating buttons.  I styled them using XML first, and I'm trying to take the XML below and make it programattic.

<Button
    android:id="@+id/buttonIdDoesntMatter"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="buttonName"
    android:drawableLeft="@drawable/imageWillChange"
    android:onClick="listener"
    android:layout_width="fill_parent">
</Button>
```

<p>This is what I have so far.  I can do everything but the drawable.</p>

<pre class="lang-java prettyprint-override"><code>linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
    new LayoutParams(
        android.view.ViewGroup.LayoutParams.FILL_PARENT,
        android.view.ViewGroup.LayoutParams.WRAP_CONTENT
    )
);

linear.addView(button);
</code>```

答:
as @Jérémy Reynaud pointing out, as described in this answer, the safest way to set the left drawable without changing the values of the other drawables (top, right, and bottom) is by using the previous values from the button with setCompoundDrawablesWithIntrinsicBounds:

```<code>Drawable leftDrawable = getContext().getResources()
                          .getDrawable(R.drawable.yourdrawable);

// Or use ContextCompat
// Drawable leftDrawable = ContextCompat.getDrawable(getContext(),
//                                        R.drawable.yourdrawable);

Drawable[] drawables = button.getCompoundDrawables();
button.setCompoundDrawablesWithIntrinsicBounds(leftDrawable,drawables[1],
                                               drawables[2], drawables[3]);
</code>```

So all your previous drawable will be preserved.

Body:
I'm dynamically creating buttons.  I styled them using XML first, and I'm trying to take the XML below and make it programattic.

<Button
    android:id="@+id/buttonIdDoesntMatter"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="buttonName"
    android:drawableLeft="@drawable/imageWillChange"
    android:onClick="listener"
    android:layout_width="fill_parent">
</Button>

This is what I have so far.  I can do everything but the drawable.

linear = (LinearLayout) findViewById(R.id.LinearView);
Button button = new Button(this);
button.setText("Button");
button.setOnClickListener(listener);
button.setLayoutParams(
    new LayoutParams(
        android.view.ViewGroup.LayoutParams.FILL_PARENT,
        android.view.ViewGroup.LayoutParams.WRAP_CONTENT
    )
);

linear.addView(button);

Body:
as @Jérémy Reynaud pointing out, as described in this answer, the safest way to set the left drawable without changing the values of the other drawables (top, right, and bottom) is by using the previous values from the button with setCompoundDrawablesWithIntrinsicBounds:

Drawable leftDrawable = getContext().getResources()
                          .getDrawable(R.drawable.yourdrawable);

// Or use ContextCompat
// Drawable leftDrawable = ContextCompat.getDrawable(getContext(),
//                                        R.drawable.yourdrawable);

Drawable[] drawables = button.getCompoundDrawables();
button.setCompoundDrawablesWithIntrinsicBounds(leftDrawable,drawables[1],
                                               drawables[2], drawables[3]);

So all your previous drawable will be preserved.


问:
How to capture git error login in shell script
i need to capture message from error login in git.

I have the following code section:

```<code>#!/bin/bash

...

git push origin master
</code>```

Then the shell script ask me fot username and password:

Username for github.com:

Password for github.com:

So I insert a invalid username and passowrd. Then Git give me a error message:

remote: Invalid username or password.

fatal: Authentication failed for https://github.com/.../.../

How can i capture these error messages in a shell script to a variable?

Thanks :)

答:
it works with me with '$?'

```<code>$ git push origin master
Username for 'https://github.com': sld,sldk
Password for 'https://sld,sldk@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
$ echo $?
128
</code>```

If the command has succeded, $? should return 0.
Just catch it in a variable (like 'var=$?') and you'll be good to go.

To catch the error message, just redirect your error output like this (stderr to file):

```<code>$ git push origin master 2>plop
Username for 'https://github.com': lskdls
Password for 'https://lskdls@github.com':
$ cat plop
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
</code>```

Or this (stderr to stdout. Use a variable to catch stdout) :

```<code>$ ploop=$(git push origin master 2>&1)
Username for 'https://github.com': skjdksd
Password for 'https://skjdksd@github.com':
$ echo $ploop
remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
</code>```

Body:
i need to capture message from error login in git.

I have the following code section:

#!/bin/bash

...

git push origin master

Then the shell script ask me fot username and password:

Username for github.com:

Password for github.com:

So I insert a invalid username and passowrd. Then Git give me a error message:

remote: Invalid username or password.

fatal: Authentication failed for https://github.com/.../.../

How can i capture these error messages in a shell script to a variable?

Thanks :)

Body:
it works with me with '$?'

$ git push origin master
Username for 'https://github.com': sld,sldk
Password for 'https://sld,sldk@github.com':
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'
$ echo $?
128

If the command has succeded, $? should return 0.
Just catch it in a variable (like 'var=$?') and you'll be good to go.

To catch the error message, just redirect your error output like this (stderr to file):

$ git push origin master 2>plop
Username for 'https://github.com': lskdls
Password for 'https://lskdls@github.com':
$ cat plop
remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'

Or this (stderr to stdout. Use a variable to catch stdout) :

$ ploop=$(git push origin master 2>&1)
Username for 'https://github.com': skjdksd
Password for 'https://skjdksd@github.com':
$ echo $ploop
remote: Invalid username or password. fatal: Authentication failed for 'https://github.com/KamelHacene/configeuh.git/'


问:
How to programmatically focus to a node in PrimeNG Tree?
Using PrimeNG, I can scroll to a TreeNode:

In html:

```<code><p-tree #mytreeid id="mytree"></p-tree>
</code>```

In Angular:

```<code>@ViewChild("mytree") mytree: Tree;
// selection is the TreeNode you want to scroll into view
scrollToSelectionPrimeNgDataTree(selection, tree, elementIdName) {
      if (tree.value !== null) {
          let index = tree.value.indexOf(selection);
              let ele = document.getElementById(elementIdName).querySelectorAll("p-treenode")[index];
              ele.scrollIntoView();
              //ele.focus();
      }
  }
</code>```

Question: How to make the TreeNode(ie. 'selection') focused? I tried to call the focus() method, but focus() is not the method of the Element.

答:
I found the solution, we only need to set the [(selection)] to the selected node:

```

Body:
Using PrimeNG, I can scroll to a TreeNode:

In html:

In Angular:

@ViewChild("mytree") mytree: Tree;
// selection is the TreeNode you want to scroll into view
scrollToSelectionPrimeNgDataTree(selection, tree, elementIdName) {
      if (tree.value !== null) {
          let index = tree.value.indexOf(selection);
              let ele = document.getElementById(elementIdName).querySelectorAll("p-treenode")[index];
              ele.scrollIntoView();
              //ele.focus();
      }
  }

Question: How to make the TreeNode(ie. 'selection') focused? I tried to call the focus() method, but focus() is not the method of the Element.

Body:
I found the solution, we only need to set the [(selection)] to the selected node:

<p-tree #mytree id="mytree" [value]="componentGroups" selectionMode="single" [(selection)]="selectedNode">

ContentLicense: CC BY-SA 4.0


问:
How to get phpexcel to keep leading 0s in phone numbers?
Here's the code i'm using right now to set the cell values. It works alright if the number has separators like . or / but when there's no separator it gets saved as int and the leading 0 is stripped    </p>

```<code>$sheet->setCellValue($letter[$j].$row_nr,$entity['Phone'], PHPExcel_Cell_DataType::TYPE_STRING);
</code>```

答:
Whenever someone proceeds like I did, this can help :

```<code>$inputFileName = 'file.xls';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objWorkSheet = $objPHPExcel->getActiveSheet();
$objWorkSheet->getCell('A1')->setValueExplicit('0029', PHPExcel_Cell_DataType::TYPE_STRING);
</code>```

As inspired by this answer. I hope this help somebody.

Body:
Here's the code i'm using right now to set the cell values. It works alright if the number has separators like . or / but when there's no separator it gets saved as int and the leading 0 is stripped

$sheet->setCellValue($letter[$j].$row_nr,$entity['Phone'], PHPExcel_Cell_DataType::TYPE_STRING);

Body:
Whenever someone proceeds like I did, this can help :

$inputFileName = 'file.xls';
$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
$objWorkSheet = $objPHPExcel->getActiveSheet();
$objWorkSheet->getCell('A1')->setValueExplicit('0029', PHPExcel_Cell_DataType::TYPE_STRING);

As inspired by this answer. I hope this help somebody.


问:
Change class property when set
I have the following class:

```<code>class Message {
    var content: [String]?

    init(content: [String]) {
        self.content = content
    }
}
</code>```

I want content to be an array of Strings, that are always uppercase. Even when lowercase text is set to content.
I don't seem to be able to use computed properties for this

答:
```<code>init(content: [String]) {

    self.content =  content
    self.setupMyProperty()

 }

 func setupMyProperty() {
        let arrCaps = self.content.map{$0.uppercased()}

       self.content.removeAll()
      self.content = arrCaps
    }
</code>```

Title: Change class property when set

Body:
I have the following class:

class Message {
    var content: [String]?

    init(content: [String]) {
        self.content = content
    }
}

I want content to be an array of Strings, that are always uppercase. Even when lowercase text is set to content.
I don't seem to be able to use computed properties for this


问:
How to make upload button submit files without second submit button php Symfony3
I have upload button. Currently when it is clicked there is a new button save showing which submits the form with the data. Is it possible after upload is clicked to open a tab in which to select files and after files are selected if Open is clicked to submit the form without the need of a second button?
Imagine I have this code

```<code><form action="/upload" method="post">
  <input type="file" name="uploadButton" value="Upload Images"/>
</form>
</code>```

Is it possible for this button to submit the form and send the data without second button save. I am using Symfony 3.3 and twig templates. I know javascript if it can help. Thank you in advance.

答:
Add an event listener to automatically submit the form when input changes:

HTML:

```<code><form id="myform" action="/upload" method="post">
  <input id="myinput" type="file" name="uploadButton" value="Upload Images"/>
</form>
</code>```

JavaScript:

```<code>var form = document.getElementById('myform');
var input = document.getElementById('myinput');

var change_running = false;
input.addEventListener('change', function(){
    if(!change_running){
        setTimeout(function(){
            change_running = true;
            form.submit();
            change_running = false;
        }, 300);
    }
});
</code>```

Body:
I have upload button. Currently when it is clicked there is a new button save showing which submits the form with the data. Is it possible after upload is clicked to open a tab in which to select files and after files are selected if Open is clicked to submit the form without the need of a second button?
Imagine I have this code

<form action="/upload" method="post">
  <input type="file" name="uploadButton" value="Upload Images"/>
</form>

Is it possible for this button to submit the form and send the data without second button save. I am using Symfony 3.3 and twig templates. I know javascript if it can help. Thank you in advance.

Body:
Add an event listener to automatically submit the form when input changes:

HTML:

<form id="myform" action="/upload" method="post">
  <input id="myinput" type="file" name="uploadButton" value="Upload Images"/>
</form>

JavaScript:

var form = document.getElementById('myform');
var input = document.getElementById('myinput');

var change_running = false;
input.addEventListener('change', function(){
    if(!change_running){
        setTimeout(function(){
            change_running = true;
            form.submit();
            change_running = false;
        }, 300);
    }
});


问:
Validating an input field if a certain radio button is checked
I have a form with multiple question each asking for a radio button selection of Pass, Fail or N/A. What I want to achieve is if the user selects Fail for any of the questions and try to submit it will then turn on validation for 3 text fields.

The user must complete all three text input fields if they select Fail on any question and can't submit unless they do so.

Also I have validation on the questions already to ensure the user selects a radio button for each field so the solution must be able to work with it as it is now. An example is of my form is

```<code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form</title>
<script>
function valbutton(thisform) {

// Question 1
myOption = -1;
    for (i=thisform.questionone_one.length-1; i > -1; i--) {
        if (thisform.questionone[i].checked) {
        myOption = i; i = -1;
        }
    }
    if (myOption == -1) {
        alert("Please select Pass, Fail or N/A for Question 1");
    return false;
    }

// Question2
myOption = -1;
    for (i=thisform.questiontwo.length-1; i > -1; i--) {
        if (thisform.questiontwo[i].checked) {
        myOption = i; i = -1;
        }
    }
    if (myOption == -1) {
        alert("Please select Pass, Fail or N/A for Question 2");
    return false;
    }

//etc...

thisform.submit();
}
</script>
</head>

<body>

<form method="post" action="send.php" enctype="multipart/form-data" class="form" name="claimform" id="claimform">

<div>1. Question? <input type="radio" name="questionone" class="radio" value="P"  /> Pass     <input name="questionone" type="radio" class="radio" value="F"  /> Fail     <inputname="questionone" type="radio" class="radio" value="N/A"  /> N/A</div>

<div>1. Question? <input type="radio" name="questiontwo" class="radio" value="P"  /> Pass     <input name="questiontwo" type="radio" class="radio" value="F"  /> Fail     <inputname="questiontwo" type="radio" class="radio" value="N/A"  /> N/A</div>

<button type="submit" title="Submit Claim" class="button" onclick="valbutton(claimform);return false;"><span><span>Submit Claim</span></span></button>
<button type="button" title="Reset" class="button" onclick="this.form.reset()"><span><span>Clear Form</span></span></button>

</form>

</body>
</html>
</code>```

Any ideas?

Also I forgot to mention I'm using Mootools in this page so any solution should work with Mootools 1.2.

答:
First of all, you should declare your variables using the var keyword. Otherwise, you pollute the global namespace, and JavaScript has to move up through the stack to find your variable.

Now, as for your question... I like to use jQuery. If you prefer to use plain old JavaScript then you can translate it.

```<code>function submitMyForm() {
  var failAnswers = $('input[type=radio]').filter(function() { return $(this).val() == "F"; });
  if (failAnswers.length > 0) {
    var blankTextFields = $('input[type=text]').filter(function() { return $(this).val() == ""; });
    if (blankTextFields.length > 0) {
      alert('Please answer the questions');
      return false;
    }
  }

  myForm.submit();
}
</code>```

Here's what we did. First we found all of the radio buttons with "F" answers. If there is at least one, we find all the text boxes with no input. If there is at least one of these, we pop up the alert message and return false. Otherwise, all is well and we submit the form.

Body:
I have a form with multiple question each asking for a radio button selection of Pass, Fail or N/A. What I want to achieve is if the user selects Fail for any of the questions and try to submit it will then turn on validation for 3 text fields.

The user must complete all three text input fields if they select Fail on any question and can't submit unless they do so.

Also I have validation on the questions already to ensure the user selects a radio button for each field so the solution must be able to work with it as it is now. An example is of my form is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Form</title>

<form method="post" action="send.php" enctype="multipart/form-data" class="form" name="claimform" id="claimform">

1. Question? <input type="radio" name="questionone" class="radio" value="P"  /> Pass     <input name="questionone" type="radio" class="radio" value="F"  /> Fail     <inputname="questionone" type="radio" class="radio" value="N/A"  /> N/A

1. Question? <input type="radio" name="questiontwo" class="radio" value="P"  /> Pass     <input name="questiontwo" type="radio" class="radio" value="F"  /> Fail     <inputname="questiontwo" type="radio" class="radio" value="N/A"  /> N/A

<button type="submit" title="Submit Claim" class="button" onclick="valbutton(claimform);return false;">Submit Claim</button>
<button type="button" title="Reset" class="button" onclick="this.form.reset()">Clear Form</button>

</form>

Any ideas?

Also I forgot to mention I'm using Mootools in this page so any solution should work with Mootools 1.2.

Body:
First of all, you should declare your variables using the var keyword. Otherwise, you pollute the global namespace, and JavaScript has to move up through the stack to find your variable.

Now, as for your question... I like to use jQuery. If you prefer to use plain old JavaScript then you can translate it.

function submitMyForm() {
  var failAnswers = $('input[type=radio]').filter(function() { return $(this).val() == "F"; });
  if (failAnswers.length > 0) {
    var blankTextFields = $('input[type=text]').filter(function() { return $(this).val() == ""; });
    if (blankTextFields.length > 0) {
      alert('Please answer the questions');
      return false;
    }
  }

  myForm.submit();
}

Here's what we did. First we found all of the radio buttons with "F" answers. If there is at least one, we find all the text boxes with no input. If there is at least one of these, we pop up the alert message and return false. Otherwise, all is well and we submit the form.


问:
Vagrant destroy execute ruby
I would like to execute a custom ruby code after doing vagrant destroy.

That's the code:

```<code>class OnDestroyMiddleware

  def initialize(app, env)
    @app = app
  end

  def call(env)
    env["config"].vm.provisioners.each do |provisioner|
      env.ui.info "Attempting to remove client #{provisioner.config.node_name}"
      `knife client show #{provisioner.config.node_name}`
      if $?.to_i == 0
        env.ui.info "Removing client #{provisioner.config.node_name}"
        `knife client delete #{provisioner.config.node_name} -y`
      end
      env.ui.info "Attempting to remove node #{provisioner.config.node_name}"
      `knife node show #{provisioner.config.node_name}`
      if $?.to_i == 0
        env.ui.info "Removing node #{provisioner.config.node_name}"
        `knife node delete #{provisioner.config.node_name} -y`
      end
    end
    @app.call(env)
  end
end
</code>```

I'm trying this but isn't working:

```<code>Vagrant::Action[:destroy].use(OnDestroyMiddleware)
</code>```

All of this code is from https://gist.github.com/skippy/1010660

I've got this error on Vagrant::Action[:destroy]

Message: NoMethodError: undefined method `[]' for Vagrant::Action:Module

答:
You can look at the vagrant trigger plugin. It allows you to run code after a specific vagrant command.

First you need to install the plugin

```<code>$ vagrant plugin install vagrant-triggers
</code>```

You'll add the code directly in your Vagrantfile, like

```<code>Vagrant.configure("2") do |config|
  # Your existing Vagrant configuration
  ...

  # run some script before the guest is destroyed
  config.trigger.after :destroy do
    info "Attempting to remove client..."
    run "knife client show .."
  end
</code>```

Title: Vagrant destroy execute ruby

Body:
I would like to execute a custom ruby code after doing vagrant destroy.

That's the code:

class OnDestroyMiddleware

  def initialize(app, env)
    @app = app
  end

  def call(env)
    env["config"].vm.provisioners.each do |provisioner|
      env.ui.info "Attempting to remove client #{provisioner.config.node_name}"
      `knife client show #{provisioner.config.node_name}`
      if $?.to_i == 0
        env.ui.info "Removing client #{provisioner.config.node_name}"
        `knife client delete #{provisioner.config.node_name} -y`
      end
      env.ui.info "Attempting to remove node #{provisioner.config.node_name}"
      `knife node show #{provisioner.config.node_name}`
      if $?.to_i == 0
        env.ui.info "Removing node #{provisioner.config.node_name}"
        `knife node delete #{provisioner.config.node_name} -y`
      end
    end
    @app.call(env)
  end
end

I'm trying this but isn't working:

Vagrant::Action[:destroy].use(OnDestroyMiddleware)

All of this code is from https://gist.github.com/skippy/1010660

I've got this error on Vagrant::Action[:destroy]

Message: NoMethodError: undefined method `[]' for Vagrant::Action:Module

Body:
You can look at the vagrant trigger plugin. It allows you to run code after a specific vagrant command.

First you need to install the plugin

$ vagrant plugin install vagrant-triggers

You'll add the code directly in your Vagrantfile, like

Vagrant.configure("2") do |config|
  # Your existing Vagrant configuration
  ...

  # run some script before the guest is destroyed
  config.trigger.after :destroy do
    info "Attempting to remove client..."
    run "knife client show .."
  end


问:
Error on inflating layout with navigation
When i inflate my layout with navigation drawer there is a error on inflating the layout.what is the problem in this layout.Please help me if someone can.
I am aded navigation_view in between drawer_layout but it cannot work and error on inflating layout

activity_main.xml

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:actionViewClass="android.support.v7.widget.SearchView"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.techweblearn.musicplayer.MainActivity"
    android:id="@+id/drawer_layout">

<include layout="@layout/activity_main_view"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start" />

</android.support.v4.widget.DrawerLayout>
</code>```

activity_main_view.xml

```<code><android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
app:actionViewClass="android.support.v7.widget.SearchView"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        style="@style/MyAppTheme"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#ffffff"
        app:tabIndicatorColor="@color/black" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:layout_marginBottom="?attr/actionBarSize"
    android:layout_marginTop="105dp"
    android:layout_below="@id/appBar"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true">

</android.support.v4.view.ViewPager>

<RelativeLayout
    android:elevation="16dp"
    android:id="@+id/design_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    app:behavior_hideable="true"
    app:behavior_peekHeight="50dp"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <fragment android:name="com.techweblearn.musicplayer.BottomPlayer"

        android:id="@+id/bottom_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>
</code>```

Log

```<code>FATAL EXCEPTION: main
                                                                          Process: com.techweblearn.musicplayer, PID: 17999
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.techweblearn.musicplayer/com.techweblearn.musicplayer.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                           Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                           Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                           Caused by: java.lang.reflect.InvocationTargetException
                                                                              at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                              at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                              at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                              at com.techweblearn.musicplayer.MainActivity.onCreate(MainActivity.java:116)
                                                                              at android.app.Activity.performCreate(Activity.java:6679)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                           Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                                              at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
                                                                              at android.content.res.Resources.getColorStateList(Resources.java:992)
                                                                              at android.content.Context.getColorStateList(Context.java:542)
                                                                              at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:65)
                                                                              at android.support.design.widget.NavigationView.createDefaultColorStateList(NavigationView.java:422)
                                                                              at android.support.design.widget.NavigationView.<init>(NavigationView.java:148)
                                                                              at android.support.design.widget.NavigationView.<init>(NavigationView.java:100)
                                                                              at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                              at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                              at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                              at com.techweblearn.musicplayer.MainActivity.onCreate(MainActivity.java:116)
                                                                              at android.app.Activity.performCreate(Activity.java:6679)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
</code>```

答:
Remove attribute app:actionViewClass="android.support.v7.widget.SearchView" from DrawerLayout and CoordinatorLayout.

Add menu and headerLayout to NavigationView.

Update your activity_main.xml as below:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.techweblearn.musicplayer.MainActivity"
    android:id="@+id/drawer_layout">

    <include layout="@layout/activity_main_view" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>
</code>```

Update your activity_main_view.xml as below:

```<code><android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            style="@style/MyAppTheme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="#ffffff"
            app:tabIndicatorColor="@color/black" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:layout_marginBottom="?attr/actionBarSize"
        android:layout_marginTop="105dp"
        android:layout_below="@id/appBar"
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true">

    </android.support.v4.view.ViewPager>

    <RelativeLayout
        android:elevation="16dp"
        android:id="@+id/design_bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        app:behavior_hideable="true"
        app:behavior_peekHeight="50dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <fragment
            android:name="com.techweblearn.musicplayer.BottomPlayer"
            android:id="@+id/bottom_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</code>```

Hope it helps!

Body:
When i inflate my layout with navigation drawer there is a error on inflating the layout.what is the problem in this layout.Please help me if someone can.
I am aded navigation_view in between drawer_layout but it cannot work and error on inflating layout

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    app:actionViewClass="android.support.v7.widget.SearchView"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.techweblearn.musicplayer.MainActivity"
    android:id="@+id/drawer_layout">

<include layout="@layout/activity_main_view"
    android:layout_height="match_parent"
    android:layout_width="match_parent"/>

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start" />

</android.support.v4.widget.DrawerLayout>

activity_main_view.xml

<android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
app:actionViewClass="android.support.v7.widget.SearchView"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/my_toolbar"
        style="@style/MyAppTheme"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tab"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:background="#ffffff"
        app:tabIndicatorColor="@color/black" />

</android.support.design.widget.AppBarLayout>

<android.support.v4.view.ViewPager
    android:layout_marginBottom="?attr/actionBarSize"
    android:layout_marginTop="105dp"
    android:layout_below="@id/appBar"
    android:id="@+id/view_pager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentLeft="true">

</android.support.v4.view.ViewPager>

<RelativeLayout
    android:elevation="16dp"
    android:id="@+id/design_bottom_sheet"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    app:behavior_hideable="true"
    app:behavior_peekHeight="50dp"
    app:layout_behavior="@string/bottom_sheet_behavior">

    <fragment android:name="com.techweblearn.musicplayer.BottomPlayer"

        android:id="@+id/bottom_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

Log

FATAL EXCEPTION: main
                                                                          Process: com.techweblearn.musicplayer, PID: 17999
                                                                          java.lang.RuntimeException: Unable to start activity ComponentInfo{com.techweblearn.musicplayer/com.techweblearn.musicplayer.MainActivity}: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2665)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                           Caused by: android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                           Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.support.design.widget.NavigationView
                                                                           Caused by: java.lang.reflect.InvocationTargetException
                                                                              at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                              at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                              at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                              at com.techweblearn.musicplayer.MainActivity.onCreate(MainActivity.java:116)
                                                                              at android.app.Activity.performCreate(Activity.java:6679)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
                                                                           Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x0
                                                                              at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:190)
                                                                              at android.content.res.Resources.getColorStateList(Resources.java:992)
                                                                              at android.content.Context.getColorStateList(Context.java:542)
                                                                              at android.support.v7.content.res.AppCompatResources.getColorStateList(AppCompatResources.java:65)
                                                                              at android.support.design.widget.NavigationView.createDefaultColorStateList(NavigationView.java:422)
                                                                              at android.support.design.widget.NavigationView.<init>(NavigationView.java:148)
                                                                              at android.support.design.widget.NavigationView.<init>(NavigationView.java:100)
                                                                              at java.lang.reflect.Constructor.newInstance0(Native Method)
                                                                              at java.lang.reflect.Constructor.newInstance(Constructor.java:430)
                                                                              at android.view.LayoutInflater.createView(LayoutInflater.java:645)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:787)
                                                                              at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                              at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                              at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                              at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                              at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:292)
                                                                              at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
                                                                              at com.techweblearn.musicplayer.MainActivity.onCreate(MainActivity.java:116)
                                                                              at android.app.Activity.performCreate(Activity.java:6679)
                                                                              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2618)
                                                                              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2726)
                                                                              at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1477)
                                                                              at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                              at android.os.Looper.loop(Looper.java:154)
                                                                              at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                              at java.lang.reflect.Method.invoke(Native Method)
                                                                              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Body:
Remove attribute app:actionViewClass="android.support.v7.widget.SearchView" from DrawerLayout and CoordinatorLayout.

Add menu and headerLayout to NavigationView.

Update your activity_main.xml as below:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.techweblearn.musicplayer.MainActivity"
    android:id="@+id/drawer_layout">

    <include layout="@layout/activity_main_view" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header_main"
        app:menu="@menu/activity_main_drawer" />

</android.support.v4.widget.DrawerLayout>

Update your activity_main_view.xml as below:

<android.support.design.widget.CoordinatorLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            style="@style/MyAppTheme"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center_vertical" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tab"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"
            android:background="#ffffff"
            app:tabIndicatorColor="@color/black" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:layout_marginBottom="?attr/actionBarSize"
        android:layout_marginTop="105dp"
        android:layout_below="@id/appBar"
        android:id="@+id/view_pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true">

    </android.support.v4.view.ViewPager>

    <RelativeLayout
        android:elevation="16dp"
        android:id="@+id/design_bottom_sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#ffffff"
        app:behavior_hideable="true"
        app:behavior_peekHeight="50dp"
        app:layout_behavior="@string/bottom_sheet_behavior">

        <fragment
            android:name="com.techweblearn.musicplayer.BottomPlayer"
            android:id="@+id/bottom_fragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

Hope it helps!


问:
Python inheritance structure
Python 3.6

I just found myself programming this type of inheritance structure (below). Where a sub class is calling methods and attributes of an object a parent has.

In my use case I'm placing code in class A that would otherwise be ugly in class B.

Almost like a reverse inheritance call or something, which doesn't seem like a good idea... (Pycharm doesn't seem to like it)

Can someone please explain what is best practice in this scenario?

Thanks!

```<code>class A(object):

    def call_class_c_method(self):
        self.class_c.do_something(self)

class B(A):

    def __init__(self, class_c):
        self.class_c = class_c
        self.begin_task()

    def begin_task(self):
        self.call_class_c_method()

class C(object):

    def do_something(self):
        print("I'm doing something super() useful")

a = A
c = C
b = B(c)
</code>```

outputs:

```<code>I'm doing something super() useful
</code>```

答:
There is nothing wrong with implementing a small feature in class A and use it as a base class for B. This pattern is known as mixin in Python. It makes a lot of sense if you want to re-use A or want to compose B from many such optional features.

But make sure your mixin is complete in itself!

The original implementation of class A depends on the derived class to set a member variable. This is a particularly ugly approach. Better define class_c as a member of A where it is used:

```<code>class A(object):

    def __init__(self, class_c):
        self.class_c = class_c

    def call_class_c_method(self):
        self.class_c.do_something()

class B(A):

    def __init__(self, class_c):
        super().__init__(class_c)
        self.begin_task()

    def begin_task(self):
        self.call_class_c_method()

class C(object):
    def do_something(self):
        print("I'm doing something super() useful")

c = C()
b = B(c)
</code>```

Title: Python inheritance structure

Body:
Python 3.6

I just found myself programming this type of inheritance structure (below). Where a sub class is calling methods and attributes of an object a parent has.

In my use case I'm placing code in class A that would otherwise be ugly in class B.

Almost like a reverse inheritance call or something, which doesn't seem like a good idea... (Pycharm doesn't seem to like it)

Can someone please explain what is best practice in this scenario?

Thanks!

class A(object):

    def call_class_c_method(self):
        self.class_c.do_something(self)

class B(A):

    def __init__(self, class_c):
        self.class_c = class_c
        self.begin_task()

    def begin_task(self):
        self.call_class_c_method()

class C(object):

    def do_something(self):
        print("I'm doing something super() useful")

a = A
c = C
b = B(c)

outputs:

I'm doing something super() useful

Body:
There is nothing wrong with implementing a small feature in class A and use it as a base class for B. This pattern is known as mixin in Python. It makes a lot of sense if you want to re-use A or want to compose B from many such optional features.

But make sure your mixin is complete in itself!

The original implementation of class A depends on the derived class to set a member variable. This is a particularly ugly approach. Better define class_c as a member of A where it is used:

class A(object):

    def __init__(self, class_c):
        self.class_c = class_c

    def call_class_c_method(self):
        self.class_c.do_something()

class B(A):

    def __init__(self, class_c):
        super().__init__(class_c)
        self.begin_task()

    def begin_task(self):
        self.call_class_c_method()

class C(object):
    def do_something(self):
        print("I'm doing something super() useful")

c = C()
b = B(c)


问:
How to generate XPath from specific text or button from URL using JAVA
I would like to get xPATH from hyperlink text or button from the webpage. For example, I want to get an xPATH of "Gmail" hyperlink text or "Google Search" button from https://www.google.com/ in JAVA.

Have someone guide me how to Generating xPATH using JAVA?

My attempt

```<code>public void xPathGenerator(String valueForXPath) throws IOException, ParserConfigurationException, SAXException, TransformerException {
    URL url = new URL("https://www.google.com/");

    DocumentBuilderFactory docBuildFac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuild = docBuildFac.newDocumentBuilder();
    Document doc = docBuild.parse(url.openStream());
    System.out.println("Node name: " + doc.getDocumentElement().getNodeName());
    System.out.println("xPath    : " + getXPath(doc.getDocumentElement(), valueForXPath));}

private String getXPath(Node documentElement, String valueForXPath) {
    for (int i = 0; i < documentElement.getChildNodes().getLength(); i++) {
        Node node = documentElement.getChildNodes().item(i);

        if(node instanceof Element) {
            if(node.getNodeName().equalsIgnoreCase(valueForXPath)) {
                return "/" + node.getNodeName();
            } else if (node.getChildNodes().getLength() > 0) {
                String xpath = getXPath(node, valueForXPath);
                if (xpath != null) {
                    return "/" + node.getNodeName() + xpath;
                }
            }
        }
    }
    return null;
}
</code>```

Thanks

答:
Try this code to search in google chrome, it worked for me.</p>

```<code>System.setProperty("webdriver.chrome.driver", "D://Driver//chromedriver.exe");
WebDriver drchrome = new ChromeDriver();
drchrome.get("https://www.google.com");
WebElement find = drchrome.findElement(By.id("lst-ib"));
find.sendKeys(new String[] {"arsenal"});
find.submit();
</code>```

Body:
I would like to get xPATH from hyperlink text or button from the webpage. For example, I want to get an xPATH of "Gmail" hyperlink text or "Google Search" button from https://www.google.com/ in JAVA.

Have someone guide me how to Generating xPATH using JAVA?

My attempt

public void xPathGenerator(String valueForXPath) throws IOException, ParserConfigurationException, SAXException, TransformerException {
    URL url = new URL("https://www.google.com/");

    DocumentBuilderFactory docBuildFac = DocumentBuilderFactory.newInstance();
    DocumentBuilder docBuild = docBuildFac.newDocumentBuilder();
    Document doc = docBuild.parse(url.openStream());
    System.out.println("Node name: " + doc.getDocumentElement().getNodeName());
    System.out.println("xPath    : " + getXPath(doc.getDocumentElement(), valueForXPath));}

private String getXPath(Node documentElement, String valueForXPath) {
    for (int i = 0; i < documentElement.getChildNodes().getLength(); i++) {
        Node node = documentElement.getChildNodes().item(i);

        if(node instanceof Element) {
            if(node.getNodeName().equalsIgnoreCase(valueForXPath)) {
                return "/" + node.getNodeName();
            } else if (node.getChildNodes().getLength() > 0) {
                String xpath = getXPath(node, valueForXPath);
                if (xpath != null) {
                    return "/" + node.getNodeName() + xpath;
                }
            }
        }
    }
    return null;
}

Thanks

Body:
Try this code to search in google chrome, it worked for me.

System.setProperty("webdriver.chrome.driver", "D://Driver//chromedriver.exe");
WebDriver drchrome = new ChromeDriver();
drchrome.get("https://www.google.com");
WebElement find = drchrome.findElement(By.id("lst-ib"));
find.sendKeys(new String[] {"arsenal"});
find.submit();


问:
Creating an overlay in CSS?
I have div that I display dynamically when certain conditions arise.

When I display the div, how can I create the effect of the background dimming and my div appearing to be prominent? much like a number of AJAX lightboxes or popups. (Thickbox, ColorBox, PrettyPhoto, etc)

I don;t quite get how they do it. I have everything else working in my own custom code except that piece.

Can anyone help me learn how?

答:
Here is an example that you can play around with.

http://jsfiddle.net/r77K8/1/

Hope this helps.

Bob

Title: Creating an overlay in CSS?


问:
Valid methods in being highlighted in red 'Unresolved Reference'
How to solve this problem? The program works. But the methods in Gogland are highlighted in red. Qt version 5.8 is added.

```<code>Gogland (1.0 Preview) 1.0 EAP
Build #GO-171.4694.61, built on June 27, 2017
Gogland EAP User
Expiration date: September 25, 2017
JRE: 1.8.0_112-release-736-b21 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.8.0-58-generic

batis@dev:~$ printenv | grep GO
GOROOT=/usr/lib/go-1.8/
GOPATH=/home/batis/gocode/

package main

import (
    "os"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    //create a window
    window := widgets.NewQMainWindow(nil, 0)

    ......

    widgets.QApplication_Exec()
}
</code>```

答:
The methods are defined in a big generated file that is not indexed by Gogland. To change the limit you should change idea.max.intellisense.filesize.

To do this, open custom properties file via Help | Edit Custom Properties menu and add something like this: idea.max.intellisense.filesize=4500 for 4.5 MB limit. The size is in Kilobytes.

Please use carefully, indexing large files may influence index update speed dramatically.

Body:
How to solve this problem? The program works. But the methods in Gogland are highlighted in red. Qt version 5.8 is added.

Gogland (1.0 Preview) 1.0 EAP
Build #GO-171.4694.61, built on June 27, 2017
Gogland EAP User
Expiration date: September 25, 2017
JRE: 1.8.0_112-release-736-b21 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Linux 4.8.0-58-generic

batis@dev:~$ printenv | grep GO
GOROOT=/usr/lib/go-1.8/
GOPATH=/home/batis/gocode/

package main

import (
    "os"
    "github.com/therecipe/qt/widgets"
)

func main() {
    widgets.NewQApplication(len(os.Args), os.Args)

    //create a window
    window := widgets.NewQMainWindow(nil, 0)

    ......

    widgets.QApplication_Exec()
}


问:
Move a part of SVN branch to another branch, replace stub
In the application I work on, I began developing a new feature. At the moment I started, I lacked the foresight of how large a feature that would be - that it would definitely grant its own branch in the repository. Then a client reported a bug in a release from before I began working on that feature, and I quickly checked the revision out, fixed the bug, got it through testing, and... uh. I don't exactly know how to check it in now so that I don't break everything

r34 is far from stable currently, and likely won't be any soon. Meanwhile the branch needs to be open for hotfixes.  So the smart approach would be to move all that work starting with the first commit introducing the big feature to a separate branch. And simultaneously not lose the local copy with the bugfix, but commit it as the head of the r10 branch.

This is what it looks like...

How can I do this without breaking anything (any more than it is already)?

答:
Create a patch between r34 and r33

revert branch 10 to r33

create branch 11 from the new commit

apply patch to the new branch 11

commit local copy to branch 10