问:
Spring MVC: Securing handler method
I'm wondering what is good approach to secure handler method in Spring MVC controller. Now i use @Secured annotation, that ensure that some method may be accessed by logged user only. But how to ensure that one logged user doesn't do something bad for other users ? For example i have method that delete item with given id. To ensure that someone can't remove other than his items i check item owner. Is better way to do something like that ?

```<code>@Secured("ROLE_USER")
@RequestMapping("/deleteitem.html")
public String delete(@RequestParam(value="id") Long id) {
    Item b = itemDAO.get(id);
    if(b.getOwner().getId().equals(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser().getId())) {
        itemDAO.delete(id);
    }
    return "redirect:/user/items.html";
}
</code>```

答: Look into Spring Security ACL (Access control list) you can create a list of permissions that users have for this object.  Permissions include read, write, delete...</p>

Title: Spring MVC: Securing handler method

Body:
I'm wondering what is good approach to secure handler method in Spring MVC controller. Now i use @Secured annotation, that ensure that some method may be accessed by logged user only. But how to ensure that one logged user doesn't do something bad for other users ? For example i have method that delete item with given id. To ensure that someone can't remove other than his items i check item owner. Is better way to do something like that ?

@Secured("ROLE_USER")
@RequestMapping("/deleteitem.html")
public String delete(@RequestParam(value="id") Long id) {
    Item b = itemDAO.get(id);
    if(b.getOwner().getId().equals(((UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser().getId())) {
        itemDAO.delete(id);
    }
    return "redirect:/user/items.html";
}


来源: stackexchange

问:
How do I avoid getting "Missing return statement" when calling a method that throws an exception, from within another method?
I have a method that handles different error codes and always throws unchecked exception. This method is used in many places across the class. When I try to call it inside another method that has not void return type as shown below:

```<code>public Object someMethod() {
   ....
   if(success){
     return result;
   } else {
      callMethodThatAlwaysThrowsUncheckedExceptions();
   }
}
</code>```

java compiler says that the method is missing return statement.

Only two options come to my mind how to solve this problem:

replace method call with its content

add a return statement just after method call that returns an empty object

However I don't really like any of these options: the first one because of code duplication and the second one because of the need to write code that will never be executed.

Is there any other way to solve this problem?

答:
I like minus's answer, but it can be a bit unreadable to users that might mistakenly think return result; will always be executed (regardless of the value of success).

As an alternative, you can change

```<code>void callMethodThatAlwaysThrowsUncheckedExceptions () {}
</code>```

to

```<code>Object callMethodThatAlwaysThrowsUncheckedExceptions () {}
</code>```

(no need to change the method body).

Now you can write

```<code>public Object someMethod() {
    ....
    if (success) {
        return result;
    } else {
        return callMethodThatAlwaysThrowsUncheckedExceptions();
    }
}
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have a method that handles different error codes and always throws unchecked exception. This method is used in many places across the class. When I try to call it inside another method that has not void return type as shown below:

public Object someMethod() {
   ....
   if(success){
     return result;
   } else {
      callMethodThatAlwaysThrowsUncheckedExceptions();
   }
}

java compiler says that the method is missing return statement.

Only two options come to my mind how to solve this problem:

replace method call with its content

add a return statement just after method call that returns an empty object

However I don't really like any of these options: the first one because of code duplication and the second one because of the need to write code that will never be executed.

Is there any other way to solve this problem?

Body:
I like minus's answer, but it can be a bit unreadable to users that might mistakenly think return result; will always be executed (regardless of the value of success).

As an alternative, you can change

void callMethodThatAlwaysThrowsUncheckedExceptions () {}

to

Object callMethodThatAlwaysThrowsUncheckedExceptions () {}

(no need to change the method body).

Now you can write

public Object someMethod() {
    ....
    if (success) {
        return result;
    } else {
        return callMethodThatAlwaysThrowsUncheckedExceptions();
    }
}


问:
postgreSQL: primary key doesn't start on 1
I made a primary key called t_id in the table of DB by using the query  t_id SERIAL PRIMARY KEY.
At the very first time, it started well on 1. Then I deleted all the data and from then, it starts on 2 even though I set it on 1.

Here's the screenshot of what I did on seq - definition on pgAdmin4 :

Anyone has an idea where is the problem ?

Thanks a lot!!

答:
Your t_id is a primary key auto incremented serial type. These are sequenced, you can set the value of the next sequence using the sequence manipulation functions.

Postgres sequence manipulation functions documentation


问:
repeating input
I want to program it like that so while taking input of num1,num2 and operation if user doesn't give input in appropriate type it ask the user again for input.</p>

```<code>operation=(input('1.add\n2.subtract\n3.multiply\n4.divide'))
num1 =int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if operation == "add" or operation == '1' :
   print(num1,"+",num2,"=", (num1+num2))
elif operation =="subtract" or operation == '2':
   print(num1,"-",num2,"=", (num1-num2))
elif operation =="multiply" or operation == '3':
   print(num1,"*",num2,"=", (num1*num2))
elif operation =="divide" or operation == '4':
   print(num1,"/",num2,"=", (num1/num2))
</code>```

答:
This code is valid because in Python values are either truthy and falsy. However, the syntax for multicondition if clause is wrong. It should be if a == something and b == anotherthing.

So it will be as follows.

if operation == "1" or operation == "add" :
    print(num1,"+",num2,"=", (num1+num2))
```

Title: repeating input

Body:
I want to program it like that so while taking input of num1,num2 and operation if user doesn't give input in appropriate type it ask the user again for input.

operation=(input('1.add\n2.subtract\n3.multiply\n4.divide'))
num1 =int(input("Enter first number: "))
num2 = int(input("Enter second number: "))

if operation == "add" or operation == '1' :
   print(num1,"+",num2,"=", (num1+num2))
elif operation =="subtract" or operation == '2':
   print(num1,"-",num2,"=", (num1-num2))
elif operation =="multiply" or operation == '3':
   print(num1,"*",num2,"=", (num1*num2))
elif operation =="divide" or operation == '4':
   print(num1,"/",num2,"=", (num1/num2))


问:
How to use jq wildcard
I have the following json:

{
   "details":{
      "car": "bmw",
      "addresses":{
         "ext-118-21-8-0-29":[
            {
               "version":4,
               "addr":"89 Psr"
            },
            {
               "version":6,
               "addr":"56 apT"
            }
         ]
      }
   }
}
```
<p>The key <code>ext-118-21-8-0-29</code> is dynamic it will change the next time and I don't know the exact value, that's why I need to use wildcard. I need to get the value of the key <code>addr</code> where version is <code>4</code>.</p>
<p>I'm expectig as output <code>89 Psr</code></p>
<p>I tried the following using the function <code>startswith()</code>.</p>
<pre class="lang-bash prettyprint-override"><code>jq '.detail.addresses | select(startswith("ext"))'
</code>```

But it end with an error.

jq: error (at :0): startswith() requires string inputs

答:
If, as suggested by part of the question, you want to confine the search to key names starting with "ext":

```<code>.details.addresses
| to_entries[]
| select(.key|startswith("ext"))
| .value[]
| select(.version == 4)
| .addr
</code>```

Towards the other end of the spectrum of permissiveness:

```<code>.details.addresses
| ..
| objects
| select(.version==4)
| .addr
</code>```

Title: How to use jq wildcard

Body:
I have the following json:

{
   "details":{
      "car": "bmw",
      "addresses":{
         "ext-118-21-8-0-29":[
            {
               "version":4,
               "addr":"89 Psr"
            },
            {
               "version":6,
               "addr":"56 apT"
            }
         ]
      }
   }
}

The key ext-118-21-8-0-29 is dynamic it will change the next time and I don't know the exact value, that's why I need to use wildcard. I need to get the value of the key addr where version is 4.

I'm expectig as output 89 Psr

I tried the following using the function startswith().

jq '.detail.addresses | select(startswith("ext"))'

But it end with an error.

jq: error (at :0): startswith() requires string inputs

Body:
If, as suggested by part of the question, you want to confine the search to key names starting with "ext":

.details.addresses
| to_entries[]
| select(.key|startswith("ext"))
| .value[]
| select(.version == 4)
| .addr

Towards the other end of the spectrum of permissiveness:

.details.addresses
| ..
| objects
| select(.version==4)
| .addr


问:
Get value based on input in two dimensional array
I have a 2 dimensional array

```<code>var years = [[-1,"0 years"], [1,"< 1 year"], [2,"1-3 years"], [3,"> 3 years"]];
</code>```

And I want to get the number of years based on user Input, which is -1,1,2,3 how can I do it in Javascript?

I'm trying using years[years_input] but I don't get the correct value.

答:
Get the first element of the array (you need to use find for edge cases like -1):

const years = [[-1,"0 years"], [1,"< 1 year"], [2,"1-3 years"], [3,"> 3 years"]];
const index = 3;
const [, res] = years.find(([n]) => n == index);
console.log(res);```

Body:
I have a 2 dimensional array

var years = [[-1,"0 years"], [1,"< 1 year"], [2,"1-3 years"], [3,"> 3 years"]];

And I want to get the number of years based on user Input, which is -1,1,2,3 how can I do it in Javascript?

I'm trying using years[years_input] but I don't get the correct value.


问:
Android How to remove Empty Space
I want to remove empty space. For example: rama chan dran should become ramachandran.

答:
```<code>String s = "rama chan dran.....";
s = s.replace(" ", "");
</code>```

ContentLicense: CC BY-SA 3.0

Title: Android How to remove Empty Space


问:
Angular material with bootstrap 4
I am building an application using Angular Material 7.3.1 and now I want to use the Bootstrap 4 Grids. After installing Bootstrap my application is padded on the left and right side like shown in the image:

How can I void this padding?

答:
I used the following in the src/styles.css file and there are no spaces any more:</p>

```<code>.container {
    max-width: 100%!important;
    padding-right: 0px!important;
    padding-left: 0px!important;
}
</code>```

Title: Angular material with bootstrap 4

Body:
I used the following in the src/styles.css file and there are no spaces any more:

.container {
    max-width: 100%!important;
    padding-right: 0px!important;
    padding-left: 0px!important;
}


问:
Getting error while adding watcher to JIRA ticket using JIRA python API
I'm trying to add watchers after creating the issue using python but while adding into after creating issue getting below error, Can anyone help?

```<code>TypeError: unbound method add_watcher() must be called with JIRA instance as first argument (got unicode instance instead)
</code>```

Code:

```<code>def aus_issue(self):
    self.issue_aus = {
        'project': {'key': 'MOS'},
        'issuetype': {'name': 'Reporting'},
        'summary': 'Test NDP Data Audit {} AUS'.format(Jira.date_create().strftime('%B')),
        'description': self.description,
        'customfield_10038': {'value': 'AUS'},
        'customfield_10052': {'value': 'Ad hoc'},
        'customfield_10053': {'value': 'Monthly'},
        "assignee": {
            "name": ""
        }, 'duedate': str(Jira.sixth_day())}

    self.create_aus = self.client.create_issue(fields=self.issue_aus, prefetch=True)
    JIRA.add_watcher(self.create_aus.id, watcher='UserName')
</code>```

答:
In your code, the instance of JIRA class is: "self.client"

For add_watcher, you need to use it as:
self.client.add_watcher(self.create_aus.id, watcher='UserName')

Body:
I'm trying to add watchers after creating the issue using python but while adding into after creating issue getting below error, Can anyone help?

TypeError: unbound method add_watcher() must be called with JIRA instance as first argument (got unicode instance instead)

Code:

def aus_issue(self):
    self.issue_aus = {
        'project': {'key': 'MOS'},
        'issuetype': {'name': 'Reporting'},
        'summary': 'Test NDP Data Audit {} AUS'.format(Jira.date_create().strftime('%B')),
        'description': self.description,
        'customfield_10038': {'value': 'AUS'},
        'customfield_10052': {'value': 'Ad hoc'},
        'customfield_10053': {'value': 'Monthly'},
        "assignee": {
            "name": ""
        }, 'duedate': str(Jira.sixth_day())}

    self.create_aus = self.client.create_issue(fields=self.issue_aus, prefetch=True)
    JIRA.add_watcher(self.create_aus.id, watcher='UserName')


问:
Cordova FileReader overrides TypeScript FileReader
when i add the cordova-plugin-file-transfer plugin, I get the following error: reader.addEventListener is not a function .

This is because Cordova FileReader class overrides typescript FileReader.

How can i prevent this?.

How can i import native FileReader class ?

This is my function:

```<code>createImageFromBlob(image: Blob) {
  let reader = new FileReader();
  reader.addEventListener("load", () => {
    this.profilePicture = reader.result;
  }, false);
  if (image) {
    reader.readAsDataURL(image);
  }
}
</code>```

答:
Rather than fighting with Typescript to use FileReader of DOM, following modification worked for me.

```<code>createImageFromBlob(image: Blob) {
  let reader = new FileReader();

  reader.onloadend = (event) => {
    if(reader.error){
      console.log(reader.error)
    } else {
      this.profilePicture = reader.result;
    }
  }
  reader.readAsDataURL(file)
}
</code>```

I don't know why the need for such modifications. Everything was working properly. Since I installed Cordova File plugin, things started to break.

Body:
when i add the cordova-plugin-file-transfer plugin, I get the following error: reader.addEventListener is not a function .

This is because Cordova FileReader class overrides typescript FileReader.

How can i prevent this?.

How can i import native FileReader class ?

This is my function:

createImageFromBlob(image: Blob) {
  let reader = new FileReader();
  reader.addEventListener("load", () => {
    this.profilePicture = reader.result;
  }, false);
  if (image) {
    reader.readAsDataURL(image);
  }
}

Body:
Rather than fighting with Typescript to use FileReader of DOM, following modification worked for me.

createImageFromBlob(image: Blob) {
  let reader = new FileReader();

  reader.onloadend = (event) => {
    if(reader.error){
      console.log(reader.error)
    } else {
      this.profilePicture = reader.result;
    }
  }
  reader.readAsDataURL(file)
}

I don't know why the need for such modifications. Everything was working properly. Since I installed Cordova File plugin, things started to break.


问:
get SHA1 fingerprint in android
I am using sketchware IDE on my android phone to make an app.
I want to enable google sign in so the user's daata on the app gets backed up to google and restore after a reinstall but it seems I need to get my app's SHA1 fingerprint and the only way i managed to find online is only valid if I use android studio as my IDE as it requires typing commands into CMD on windows or mac.

How can I get that fingerprint on my android phone instead of a PC?

答:
From what I can see on their First Time Publishing Guide, Sketchware handles signing for release APKs. This means you aren't the one who has the release keystore file. In the Firebase guide, they ask to skip providing a debug key.

I think it would be best if you contacted their support to get an understanding of how they handle APK signing. Integration of Google Sign In is quite common, so they should have a method in place.

Title: get SHA1 fingerprint in android


问:
Reading in only part of a Stata .DTA file in R
I apologize in advance if this has a simple answer somewhere.  It seems like the kind of thing that would, but I can't seem to locate it in the help files, by searching SO, or by Googling.

I'm working with some datasets that are several GB right now.  It's enough to fit in memory on one of the cluster nodes I have access to, but takes quite a bit of time to load.  For many debugging/programming activities with this data, I don't need the entire file loaded, just the first few thousand observations to have a dataset on which to test code.  I can of course just read the whole file in and subset, but I was wondering if there's a way to tell read.dta() to only read in the first N rows?  This would of course be much faster.

I could also use a proper format like .csv and then use read.csv()'s nrows argument, but then I'd lose the factor labels in the Stata dataset (and have to recreate quite a few GB of data from someone else's code that's feeding in to this project.  So a direct solution on .dta files is preferred.

答:
To follow up on Joris Meys: For this kind of thing, I use a "test" data set and the "real" data set, each in separate folders.  I keep a macro at the top of the .do file (with if/then statements below) to (1) take a sample of the data and (2) point input/output to the right folder containing one or the other. I probably do it different for every project, but something like this:

data creation .do file

```<code>blah blah blah
save                  using data/myfile.dta
save if uniform()<.05 using test_data/myfile.dta   // or bsample, then save for panel data
</code>```

analysis .do file

```<code>local test = "test_"
// when you're ready to run the file with all the data, use the following
// local test = ""

use `test'data/myfile.dta
blah blah blah
outreg2 ... using `test'output/mytable.txt
</code>```

Body:
To follow up on Joris Meys: For this kind of thing, I use a "test" data set and the "real" data set, each in separate folders.  I keep a macro at the top of the .do file (with if/then statements below) to (1) take a sample of the data and (2) point input/output to the right folder containing one or the other. I probably do it different for every project, but something like this:

data creation .do file

blah blah blah
save                  using data/myfile.dta
save if uniform()<.05 using test_data/myfile.dta   // or bsample, then save for panel data

analysis .do file

local test = "test_"
// when you're ready to run the file with all the data, use the following
// local test = ""

use `test'data/myfile.dta
blah blah blah
outreg2 ... using `test'output/mytable.txt


问:
Plotting nodes with no links using igraph and R
I'm plotting a network as below using the igraph package, but I want to be able to show all of the nodes (Authors) in the plot, even those authors who do not have a joint paper with someone else. Is that possible?

```<code>PubID <- c("169759","174843","174843","174843","174843","174843","171051","171051","171051","171719","171719","171719","169759","173847","173847","177427")
Author <- c("ZJ","RA","DJ","JP","GS","Tv","MC","JR","CW","PB","MD","FO","FO","RA","DJ","KS")
dt <- data.frame(Author,PubID)
library(tidyverse)
library(igraph)
dt %>%
  mutate(author_id = as.integer(Author)) -> dt
dt %>%
  inner_join(dt, by = "PubID") %>%
  filter(author_id.x < author_id.y) %>%
  count(Author.x, Author.y) %>%
  graph_from_data_frame(directed = FALSE) -> g1
plot(g1)
as_data_frame(g1, what = "edges")
</code>```

I would want to show the network, and then show the "KS" author as a single node in the plot.

答:
First we find all those who aren't present yet:

```<code>(rest <- setdiff(Author, V(g1)$name))
# [1] "KS"
</code>```

And then add them with

```<code>g1 <- add.vertices(g1, length(rest), attr = list(name = rest))
</code>```

Body:
I'm plotting a network as below using the igraph package, but I want to be able to show all of the nodes (Authors) in the plot, even those authors who do not have a joint paper with someone else. Is that possible?

PubID <- c("169759","174843","174843","174843","174843","174843","171051","171051","171051","171719","171719","171719","169759","173847","173847","177427")
Author <- c("ZJ","RA","DJ","JP","GS","Tv","MC","JR","CW","PB","MD","FO","FO","RA","DJ","KS")
dt <- data.frame(Author,PubID)
library(tidyverse)
library(igraph)
dt %>%
  mutate(author_id = as.integer(Author)) -> dt
dt %>%
  inner_join(dt, by = "PubID") %>%
  filter(author_id.x < author_id.y) %>%
  count(Author.x, Author.y) %>%
  graph_from_data_frame(directed = FALSE) -> g1
plot(g1)
as_data_frame(g1, what = "edges")

I would want to show the network, and then show the "KS" author as a single node in the plot.

Body:
First we find all those who aren't present yet:

(rest <- setdiff(Author, V(g1)$name))
# [1] "KS"

And then add them with

g1 <- add.vertices(g1, length(rest), attr = list(name = rest))


问:
How to display progress indicator in flutter?
I am trying to show a progress indicator when i am logging in. I have created a boolean value to toggle when I want to show and hide the indicator, however i am not able to figure out where exactly i should show the indicator.

I can add it as one of my widgets in my Container where I am displaying all other screen widgets, however i dont want it to interfere with other widgets and rather show on top of all of them.  How can I achieve this?  How can I achieve this?

Thanks in advance.

My code

```<code>import ....

class Login extends StatefulWidget{
...
}

class _LoginState extends State<Login> {

bool _loading = false;

  @override
  Widget build(BuildContext context){

    Future<Map<String, dynamic>> getData() async {
      var client = http.Client();

      //to SHOW Indicator
      setState(() {
        _loading = true;
      });

      var response = await client
          .post(
          Uri.encodeFull(
              ' api url '),
          body:
        {"email":"$username","password":"$password"}

      ).whenComplete(
          client.close);

      var res = json.decode(response.body);

      //to HIDE indicator
      setState(() {
        _loading = false;
      });

      if(response.statusCode <200 || response.statusCode > 400){
        print("Error");
         throwError();
      }
      if(response.statusCode == 200 ){
        widget.onSignedIn();
      }

      if (!mounted)
        return {'success': false};

      return json.decode(response.body);
    }

    Container view = Container(
      ....
    );

    return Scaffold(
        resizeToAvoidBottomPadding: false,
      body: view

    );
  }
}
</code>```

答:
As CopsOnRoad mentioned, you must use Stack if you want to place multiple Widgets that do not interfere with each other.

Also, Dart 2.3 introduced collection if. With it, you can add an item to your Collection only if a condition is true.

Stack(
  alignment: Alignment.center,
  children: [
    Container(child: ...),
    if (_loading) CircularProgressIndicator(),
  ],
)
```

Body:
I am trying to show a progress indicator when i am logging in. I have created a boolean value to toggle when I want to show and hide the indicator, however i am not able to figure out where exactly i should show the indicator.

I can add it as one of my widgets in my Container where I am displaying all other screen widgets, however i dont want it to interfere with other widgets and rather show on top of all of them.  How can I achieve this?  How can I achieve this?

Thanks in advance.

My code

import ....

class Login extends StatefulWidget{
...
}

class _LoginState extends State<Login> {

bool _loading = false;

  @override
  Widget build(BuildContext context){

    Future<Map<String, dynamic>> getData() async {
      var client = http.Client();

      //to SHOW Indicator
      setState(() {
        _loading = true;
      });

      var response = await client
          .post(
          Uri.encodeFull(
              ' api url '),
          body:
        {"email":"$username","password":"$password"}

      ).whenComplete(
          client.close);

      var res = json.decode(response.body);

      //to HIDE indicator
      setState(() {
        _loading = false;
      });

      if(response.statusCode <200 || response.statusCode > 400){
        print("Error");
         throwError();
      }
      if(response.statusCode == 200 ){
        widget.onSignedIn();
      }

      if (!mounted)
        return {'success': false};

      return json.decode(response.body);
    }

    Container view = Container(
      ....
    );

    return Scaffold(
        resizeToAvoidBottomPadding: false,
      body: view

    );
  }
}


问:
Order items in a ItemsControl from right top to left bottom
I'm trying to set a list in an ItemsControl in one of the views of my WPF application.

The problem is I want an other order of my items which are displayed in the control.
Prmiary, the ItemsControl displays items left to right and top to bottom :

```<code>1  2  3  4   5   6
7  8  9  10  11  12
</code>```

However, I want to display my items in a other way - from right top to left bottom - like this :

```<code>11  9   7  5  3  1
12  10  8  6  4  2
</code>```

My current ItemsControl is :

```<code>        Grid.Column="1"
        BorderThickness="1"
        BorderBrush="{DynamicResource WindowTitleColorBrush}">
    <ItemsControl ItemsSource="{Binding Truck.Containers}">
         <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                  <UniformGrid Rows="2" />
              </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>
    </ItemsControl>
</Border>
</code>```

I cannot just reorder my list by descending in the viewmodel as it will start with 12 and finish with 1 and not 11 - 2.
Is there an other way to display my list in the order I want ?

答:
I think you can follow one of 3 solutions:

Order your items as you want in View Model

Use CollectionViewSource - do your custom ordering there

Create a custom Panel that orders items as you want, and use it as ItemsPanelTemplate. To create a custom panel, create a custom class and inherit from Panel or UniformGrid. Than override two methods:

MeasureOverride - to determine the required size of the panel
according to the desired size of the child elements and the available
space.

ArrangeOverride - to arrange the elements in the finally
available space. The final size can be smaller than the requested.

More about custom panels in this msdn link and this tutorial.

You can also take a look at UniformGrid source code on msdn.

Body:
I'm trying to set a list in an ItemsControl in one of the views of my WPF application.

The problem is I want an other order of my items which are displayed in the control.
Prmiary, the ItemsControl displays items left to right and top to bottom :

1  2  3  4   5   6
7  8  9  10  11  12

However, I want to display my items in a other way - from right top to left bottom - like this :

11  9   7  5  3  1
12  10  8  6  4  2

My current ItemsControl is :

        Grid.Column="1"
        BorderThickness="1"
        BorderBrush="{DynamicResource WindowTitleColorBrush}">
    <ItemsControl ItemsSource="{Binding Truck.Containers}">
         <ItemsControl.ItemsPanel>
              <ItemsPanelTemplate>
                  <UniformGrid Rows="2" />
              </ItemsPanelTemplate>
          </ItemsControl.ItemsPanel>
    </ItemsControl>
</Border>

I cannot just reorder my list by descending in the viewmodel as it will start with 12 and finish with 1 and not 11 - 2.
Is there an other way to display my list in the order I want ?


问:
When does image.setImageResource() set the image resource inside a function?
Goal: To click on an image in an app and get it to fade out to make a different image appear.

My Method: To make the 1st image fade away after 2000ms and AFTER THAT change the image resource of the 1st image to the 2nd image to make the 2nd image appear

I have a correct solution which was provided by my instructor, so I dont want any correct solution for this. What i want to know is why is my solution not working, i.e why is setImageResource() setting the Image1 to Image 2 at the beginning despite calling it at the end

This is the fade function i have created which the image1 goes to when it is clicked

public void fade(View view){

```<code>    ImageView image1 = findViewById(R.id.image1);
    image1.animate().alpha(0f).setDuration(2000);

    image1.setImageResource(R.drawable.cat2);
}
</code>```

Actual Output: Image 1 changes to Image 2 as soon as I click it and then Image 2 fades away

Problem: Inspite of calling setImageResource() at the end of the code, it actually sets the image resource at the beginning

答:
I think this will be help to you:

Fade In Fade Out Android Animation in Java

so use in onClickListener like this:

```<code>  image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                image1.setVisibility(View.GONE);

                //Animation...

                image2.setVisibility(View.VISIBLE);

            }
        });
</code>```

Body:
Goal: To click on an image in an app and get it to fade out to make a different image appear.

My Method: To make the 1st image fade away after 2000ms and AFTER THAT change the image resource of the 1st image to the 2nd image to make the 2nd image appear

I have a correct solution which was provided by my instructor, so I dont want any correct solution for this. What i want to know is why is my solution not working, i.e why is setImageResource() setting the Image1 to Image 2 at the beginning despite calling it at the end

This is the fade function i have created which the image1 goes to when it is clicked

public void fade(View view){

    ImageView image1 = findViewById(R.id.image1);
    image1.animate().alpha(0f).setDuration(2000);

    image1.setImageResource(R.drawable.cat2);
}

Actual Output: Image 1 changes to Image 2 as soon as I click it and then Image 2 fades away

Problem: Inspite of calling setImageResource() at the end of the code, it actually sets the image resource at the beginning

Body:
I think this will be help to you:

Fade In Fade Out Android Animation in Java

so use in onClickListener like this:

  image1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                image1.setVisibility(View.GONE);

                //Animation...

                image2.setVisibility(View.VISIBLE);

            }
        });


问:
How to keep div elements at bottom of page
I have a two-columned div element that I need to have at the bottom of the page to act as a footer. The problem is I have tried using position:fixed and bottom:0 to make the element appear at the bottom. This works but only brings one of the #column divs down to the bottom, the other disappears. I would appreciate any assistance.

Code:

/* ~ Copyright (c) Macleay Netball Association (made by Tom Carpenter for Year 11 IPT Assessment Task #2.) 2019. */

html>body {
  background: none;
  padding: 0;
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Trebuchet MS', sans-serif;
  /* Trebuchet MS as main font throughout website, sans-serif acting as a backup */
}

#wrapper {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  position: absolute;
  background: #1B315E;
}

::-webkit-scrollbar {
  display: none;
}

* {
  box-sizing: border-box;
  /* Alignment of DropDown Navigation Menu and Slideshow */
}

.navigation {
  background: #444;
  overflow: hidden;
  top: 0;
}

.menuDropDown {
  overflow: hidden;
  float: left;
}

.menuDropDown>#menuButton {
  font-size: 12px;
  padding: 16px 16px;
  /* Will result in final height of navigation */
  margin: 0;
  outline: none;
  border: none;
  font: inherit;
  background: inherit;
  color: #FFF;
}

#menuButton:hover,
.navigation>.menuDropDown:hover>#menuButton {
  border: none;
  outline: none;
  background: #666;
  color: #1B315E;
}

.menuDropDown:hover>.menuContent {
  display: block;
}

.menuContent {
  display: none;
  position: absolute;
  background: none;
  width: 100%;
  left: 0;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.menuRow:after {
  display: table;
  clear: both;
  content: "";
}

.menuColumn {
  width: 25%;
  height: 100px;
  overflow-y: auto;
  padding: 5px;
  float: left;
  background: #666;
}

.menuColumn>a {
  float: none;
  display: block;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
  padding: 8px;
  color: #1B315E;
}

.menuColumn>a.current {
  background: #777;
}

.menuColumn>a:hover {
  background: #888;
}

.logo {
  float: right;
  padding-right: 10px;
  width: 60px;
  height: 50px;
}

.main {
  width: 100%;
  height: calc(100vh - 43px);
  float: left;
  background: none;
  position: absolute;
  overflow: auto;
  padding: 8px;
}

.mainHeader {
  color: #FFF;
  text-align: center;
}

.mainImg {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

.mainBody {
  color: #FFF;
  padding: 8px;
}

.row:after {
  content: "";
  clear: both;
  display: table;
}

.column {
  float: left;
  width: 33.33%;
  padding: 8px;
}

#column {
  float: left;
  width: 50%;
  padding: 8px;
  background: #888;
  bottom: 0;
}

.sponsers {
  float: left;
  width: 20%;
  padding: 8px;
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}

.sponsers:hover {
  -webkit-filter: grayscale(80%);
  filter: grayscale(80%);
}

.slideshow {
  /* Slideshow Container containing Images, Sliders and Captions */
  position: relative;
  margin: auto;
  max-width: 1000px;
}

.slides {
  display: none;
}

.slideshowImages {
  width: 100%;
}

.slideButton {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  padding: 16px 32px;
  font-size: 18px;
  text-align: center;
  border-radius: 10px;
  font-weight: bold;
}

.mnaHeader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.slideButton:hover {
  background: #666;
}

.previous,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: #FFF;
  font-weight: bold;
  font-size: 18px;
  transition: 0.3s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

.previous:hover,
.next:hover {
  background: rgba(0, 0, 0, 0.8);
}

table {
  width: 100%;
  font-size: 16px;
  color: #FFF;
}

.tableCaption {
  font-weight: bold;
  font-size: 18px;
  color: #33CC33;
}

table,
th,
td {
  border-collapse: collapse;
  border: 2px solid #888;
}

th,
td {
  padding: 8px;
  text-align: left;
}

#headerTable {
  width: 33.33%;
  background: #888;
  font-size: 18px;
  color: #33CC33;
}

.linkProp {
  color: #FFF;
  text-decoration: underline;
}

.newsPanel {
  width: 100%;
  background: #888;
  height: 135px;
}

.imgNewsPreview {
  width: 215px;
  height: 135px;
  padding: 4px;
  float: left;
}

.newsHeaderPreview {
  color: #FFF;
  margin-top: 0px;
}

.newsBodyPreview {
  color: #FFF;
  margin-top: -12px;
}

.caption {
  color: #33CC33;
  text-align: center;
  position: absolute;
  font-size: 20px;
  width: 100%;
  padding: 8px 12px;
  bottom: 16px;
}

.collapsible {
  background: #888;
  color: #FFF;
  font-weight: bold;
  width: 100%;
  padding: 18px;
  cursor: pointer;
  font-size: 16px;
  outline: none;
  border: none;
  text-align: left;
}

.active,
.collapsible:hover {
  background: #666;
}

.collapsible:after {
  content: '\002B';
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 4px;
}

.active:after {
  content: '\2212';
}

.contentCollapsible {
  padding: 0px 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background: #F8F8F8;
}

.fade {
  -webkit-animation-name: fade;
  /* To work on Safari (Apple) */
  -webkit-animation-duration: 1s;
  /* To work on Safari (Apple) */
  animation-name: fade;
  animation-duration: 1s;
}

.buttonReturn {
  position: absolute;
  margin-left: 20px;
  margin-top: 20px;
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  font-size: 36px;
  text-align: center;
  border-radius: 50%;
  font-weight: bold;
}

.videoProp {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  height: 400px;
}

@-webkit-keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@media screen and (max-width: 600px) {
  /* Stacks navigation menu acting for the site to be responsive */
  .menuColumn {
    width: 100%;
    height: auto;
  }
}

@media screen and (max-width: 800px) {
  /* Stacks Image Header on Top - acting as responsive */
  .column,
  #column {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Responsive Sponser Images */
  .sponsers {
    width: 33.33%;
  }
}

@media screen and (max-width: 800px) {
  /* Increases video resolution as screen reduces */
  .videoProp {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Reduces font-size as screen resolution lowers */
  .newsBodyPreview {
    font-size: 14px;
  }
}

@media screen and (max-width: 300px) {
  /* Reduces font-sizes within the slideshow
 */
  .previous,
  .next,
  .caption {
    font-size: 14px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE HTML>
<!--
 ~ Copyright (c) Macleay Netball Association (made by Tom Carpenter for Year 11 IPT Assessment Task #2.) 2019.
-->
<html lang="en-AU">

<head>
  <title>Contact Us — Macleay Netball Association</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
  <link rel="stylesheet" href="../style.css" type="text/css">
  <!-- Internal Stylesheet -->
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <!-- External Font Stylesheet -->
  <link rel="shortcut icon" href="../Assets/Img/mnaHeader.png">
  <!-- Tab Browser Icon (Favicon) -->
</head>

<body>
  <div id="wrapper">
    <div class="navigation">
      <div class="menuDropDown">
        <button id="menuButton" title="Navigation Menu"><i class="fas fa-bars"></i> Menu</button>
        <div class="menuContent">
          <div class="menuRow">
            <div class="menuColumn">
              <i class="fas fa-home"></i> Home
              <i class="fas fa-address-book"></i> Association Contacts
            </div>
            <div class="menuColumn">
              <i class="fas fa-user-friends"></i> Weekly Draw
              <i class="far fa-newspaper"></i> News
            </div>
            <div class="menuColumn">
              <i class="fas fa-bookmark"></i> Quick Links
              <i class="fas fa-certificate"></i> Representative Teams
            </div>
            <div class="menuColumn">
              <i class="fas fa-file"></i> Documentation
              <i class="fas fa-phone"></i> Contact Us
            </div>
          </div>
        </div>
      </div>
      <img src="../Assets/Img/mnaHeader.png" alt="Macleay Netball Association" title="Macleay Netball Association" class="logo">
      <!-- Macleay Netball Association Main Logo -->
    </div>
    <!-- End of Navigation -->
    <div class="main">
      <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3417.0548484369647!2d152.83521681537312!3d-31.080401281517187!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6b9ddf84d6da904b%3A0xfc941d1ded8f7a25!2sPam+Guyer+Netball+Centre!5e0!3m2!1sen!2sau!4v1559129788713!5m2!1sen!2sau"
        width="100%" height="400px" frameborder="0" style="border:0" allowfullscreen></iframe>
      <!-- Google Maps Embed -->
      <br>

      <div class="row">
        <div id="column">1</div>
        <div id="column">2</div>
      </div>
      <!-- End of Footer -->
    </div>
    <!-- End of Main -->
  </div>
  <!-- End of Wrapper -->
</body>

</html></code>```

Attached are some images if I put position:fixed bottom:0 in the #column CSS Code. Only Column 2 goes down, 1 is hidden.

答:
Both 1 and 2 are fixed to the bottom. Only the float: left has no effect here and they are at the exactly same position. The 2 is in front of 1 and latter is not visible behind 2

Do this instead.

```<code><div class="row footer">
  <div id="column">1</div>
  <div id="column">2</div>
</div>
</code>```

```<code>.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}
</code>```

/* ~ Copyright (c) Macleay Netball Association (made by Tom Carpenter for Year 11 IPT Assessment Task #2.) 2019. */

html>body {
  background: none;
  padding: 0;
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Trebuchet MS', sans-serif;
  /* Trebuchet MS as main font throughout website, sans-serif acting as a backup */
}

#wrapper {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  position: absolute;
  background: #1B315E;
}

::-webkit-scrollbar {
  display: none;
}

* {
  box-sizing: border-box;
  /* Alignment of DropDown Navigation Menu and Slideshow */
}

.navigation {
  background: #444;
  overflow: hidden;
  top: 0;
}

.menuDropDown {
  overflow: hidden;
  float: left;
}

.menuDropDown>#menuButton {
  font-size: 12px;
  padding: 16px 16px;
  /* Will result in final height of navigation */
  margin: 0;
  outline: none;
  border: none;
  font: inherit;
  background: inherit;
  color: #FFF;
}

#menuButton:hover,
.navigation>.menuDropDown:hover>#menuButton {
  border: none;
  outline: none;
  background: #666;
  color: #1B315E;
}

.menuDropDown:hover>.menuContent {
  display: block;
}

.menuContent {
  display: none;
  position: absolute;
  background: none;
  width: 100%;
  left: 0;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.menuRow:after {
  display: table;
  clear: both;
  content: "";
}

.menuColumn {
  width: 25%;
  height: 100px;
  overflow-y: auto;
  padding: 5px;
  float: left;
  background: #666;
}

.menuColumn>a {
  float: none;
  display: block;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
  padding: 8px;
  color: #1B315E;
}

.menuColumn>a.current {
  background: #777;
}

.menuColumn>a:hover {
  background: #888;
}

.logo {
  float: right;
  padding-right: 10px;
  width: 60px;
  height: 50px;
}

.main {
  width: 100%;
  height: calc(100vh - 43px);
  float: left;
  background: none;
  position: absolute;
  overflow: auto;
  padding: 8px;
}

.mainHeader {
  color: #FFF;
  text-align: center;
}

.mainImg {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

.mainBody {
  color: #FFF;
  padding: 8px;
}

.row:after {
  content: "";
  clear: both;
  display: table;
}

.column {
  float: left;
  width: 33.33%;
  padding: 8px;
}

#column {
  float: left;
  width: 50%;
  padding: 8px;
  background: #888;
  bottom: 0;
}

.sponsers {
  float: left;
  width: 20%;
  padding: 8px;
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}

.sponsers:hover {
  -webkit-filter: grayscale(80%);
  filter: grayscale(80%);
}

.slideshow {
  /* Slideshow Container containing Images, Sliders and Captions */
  position: relative;
  margin: auto;
  max-width: 1000px;
}

.slides {
  display: none;
}

.slideshowImages {
  width: 100%;
}

.slideButton {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  padding: 16px 32px;
  font-size: 18px;
  text-align: center;
  border-radius: 10px;
  font-weight: bold;
}

.mnaHeader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.slideButton:hover {
  background: #666;
}

.previous,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: #FFF;
  font-weight: bold;
  font-size: 18px;
  transition: 0.3s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

.previous:hover,
.next:hover {
  background: rgba(0, 0, 0, 0.8);
}

table {
  width: 100%;
  font-size: 16px;
  color: #FFF;
}

.tableCaption {
  font-weight: bold;
  font-size: 18px;
  color: #33CC33;
}

table,
th,
td {
  border-collapse: collapse;
  border: 2px solid #888;
}

th,
td {
  padding: 8px;
  text-align: left;
}

#headerTable {
  width: 33.33%;
  background: #888;
  font-size: 18px;
  color: #33CC33;
}

.linkProp {
  color: #FFF;
  text-decoration: underline;
}

.newsPanel {
  width: 100%;
  background: #888;
  height: 135px;
}

.imgNewsPreview {
  width: 215px;
  height: 135px;
  padding: 4px;
  float: left;
}

.newsHeaderPreview {
  color: #FFF;
  margin-top: 0px;
}

.newsBodyPreview {
  color: #FFF;
  margin-top: -12px;
}

.caption {
  color: #33CC33;
  text-align: center;
  position: absolute;
  font-size: 20px;
  width: 100%;
  padding: 8px 12px;
  bottom: 16px;
}

.collapsible {
  background: #888;
  color: #FFF;
  font-weight: bold;
  width: 100%;
  padding: 18px;
  cursor: pointer;
  font-size: 16px;
  outline: none;
  border: none;
  text-align: left;
}

.active,
.collapsible:hover {
  background: #666;
}

.collapsible:after {
  content: '\002B';
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 4px;
}

.active:after {
  content: '\2212';
}

.contentCollapsible {
  padding: 0px 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background: #F8F8F8;
}

.fade {
  -webkit-animation-name: fade;
  /* To work on Safari (Apple) */
  -webkit-animation-duration: 1s;
  /* To work on Safari (Apple) */
  animation-name: fade;
  animation-duration: 1s;
}

.buttonReturn {
  position: absolute;
  margin-left: 20px;
  margin-top: 20px;
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  font-size: 36px;
  text-align: center;
  border-radius: 50%;
  font-weight: bold;
}

.videoProp {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  height: 400px;
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}
@-webkit-keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@media screen and (max-width: 600px) {
  /* Stacks navigation menu acting for the site to be responsive */
  .menuColumn {
    width: 100%;
    height: auto;
  }
}

@media screen and (max-width: 800px) {
  /* Stacks Image Header on Top - acting as responsive */
  .column,
  #column {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Responsive Sponser Images */
  .sponsers {
    width: 33.33%;
  }
}

@media screen and (max-width: 800px) {
  /* Increases video resolution as screen reduces */
  .videoProp {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Reduces font-size as screen resolution lowers */
  .newsBodyPreview {
    font-size: 14px;
  }
}

@media screen and (max-width: 300px) {
  /* Reduces font-sizes within the slideshow
 */
  .previous,
  .next,
  .caption {
    font-size: 14px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<div id="wrapper">
  <div class="navigation">
    <div class="menuDropDown">
      <button id="menuButton" title="Navigation Menu"><i class="fas fa-bars"></i> Menu</button>
      <div class="menuContent">
        <div class="menuRow">
          <div class="menuColumn">
            <i class="fas fa-home"></i> Home
            <i class="fas fa-address-book"></i> Association Contacts
          </div>
          <div class="menuColumn">
            <i class="fas fa-user-friends"></i> Weekly Draw
            <i class="far fa-newspaper"></i> News
          </div>
          <div class="menuColumn">
            <i class="fas fa-bookmark"></i> Quick Links
            <i class="fas fa-certificate"></i> Representative Teams
          </div>
          <div class="menuColumn">
            <i class="fas fa-file"></i> Documentation
            <i class="fas fa-phone"></i> Contact Us
          </div>
        </div>
      </div>
    </div>
    <img src="../Assets/Img/mnaHeader.png" alt="Macleay Netball Association" title="Macleay Netball Association" class="logo">
    <!-- Macleay Netball Association Main Logo -->
  </div>
  <!-- End of Navigation -->
  <div class="main">
    <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3417.0548484369647!2d152.83521681537312!3d-31.080401281517187!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6b9ddf84d6da904b%3A0xfc941d1ded8f7a25!2sPam+Guyer+Netball+Centre!5e0!3m2!1sen!2sau!4v1559129788713!5m2!1sen!2sau"
      width="100%" height="400px" frameborder="0" style="border:0" allowfullscreen></iframe>
    <!-- Google Maps Embed -->
    <br>

    <div class="row footer">
      <div id="column">1</div>
      <div id="column">2</div>
    </div>
    <!-- End of Footer -->
  </div>
  <!-- End of Main -->
</div>
<!-- End of Wrapper --></code>```

Body:
I have a two-columned div element that I need to have at the bottom of the page to act as a footer. The problem is I have tried using position:fixed and bottom:0 to make the element appear at the bottom. This works but only brings one of the #column divs down to the bottom, the other disappears. I would appreciate any assistance.

Code:

/* ~ Copyright (c) Macleay Netball Association (made by Tom Carpenter for Year 11 IPT Assessment Task #2.) 2019. */

html>body {
  background: none;
  padding: 0;
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Trebuchet MS', sans-serif;
  /* Trebuchet MS as main font throughout website, sans-serif acting as a backup */
}

#wrapper {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  position: absolute;
  background: #1B315E;
}

::-webkit-scrollbar {
  display: none;
}

* {
  box-sizing: border-box;
  /* Alignment of DropDown Navigation Menu and Slideshow */
}

.navigation {
  background: #444;
  overflow: hidden;
  top: 0;
}

.menuDropDown {
  overflow: hidden;
  float: left;
}

.menuDropDown>#menuButton {
  font-size: 12px;
  padding: 16px 16px;
  /* Will result in final height of navigation */
  margin: 0;
  outline: none;
  border: none;
  font: inherit;
  background: inherit;
  color: #FFF;
}

#menuButton:hover,
.navigation>.menuDropDown:hover>#menuButton {
  border: none;
  outline: none;
  background: #666;
  color: #1B315E;
}

.menuDropDown:hover>.menuContent {
  display: block;
}

.menuContent {
  display: none;
  position: absolute;
  background: none;
  width: 100%;
  left: 0;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.menuRow:after {
  display: table;
  clear: both;
  content: "";
}

.menuColumn {
  width: 25%;
  height: 100px;
  overflow-y: auto;
  padding: 5px;
  float: left;
  background: #666;
}

.menuColumn>a {
  float: none;
  display: block;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
  padding: 8px;
  color: #1B315E;
}

.menuColumn>a.current {
  background: #777;
}

.menuColumn>a:hover {
  background: #888;
}

.logo {
  float: right;
  padding-right: 10px;
  width: 60px;
  height: 50px;
}

.main {
  width: 100%;
  height: calc(100vh - 43px);
  float: left;
  background: none;
  position: absolute;
  overflow: auto;
  padding: 8px;
}

.mainHeader {
  color: #FFF;
  text-align: center;
}

.mainImg {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

.mainBody {
  color: #FFF;
  padding: 8px;
}

.row:after {
  content: "";
  clear: both;
  display: table;
}

.column {
  float: left;
  width: 33.33%;
  padding: 8px;
}

#column {
  float: left;
  width: 50%;
  padding: 8px;
  background: #888;
  bottom: 0;
}

.sponsers {
  float: left;
  width: 20%;
  padding: 8px;
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}

.sponsers:hover {
  -webkit-filter: grayscale(80%);
  filter: grayscale(80%);
}

.slideshow {
  /* Slideshow Container containing Images, Sliders and Captions */
  position: relative;
  margin: auto;
  max-width: 1000px;
}

.slides {
  display: none;
}

.slideshowImages {
  width: 100%;
}

.slideButton {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  padding: 16px 32px;
  font-size: 18px;
  text-align: center;
  border-radius: 10px;
  font-weight: bold;
}

.mnaHeader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.slideButton:hover {
  background: #666;
}

.previous,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: #FFF;
  font-weight: bold;
  font-size: 18px;
  transition: 0.3s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

.previous:hover,
.next:hover {
  background: rgba(0, 0, 0, 0.8);
}

table {
  width: 100%;
  font-size: 16px;
  color: #FFF;
}

.tableCaption {
  font-weight: bold;
  font-size: 18px;
  color: #33CC33;
}

table,
th,
td {
  border-collapse: collapse;
  border: 2px solid #888;
}

th,
td {
  padding: 8px;
  text-align: left;
}

#headerTable {
  width: 33.33%;
  background: #888;
  font-size: 18px;
  color: #33CC33;
}

.linkProp {
  color: #FFF;
  text-decoration: underline;
}

.newsPanel {
  width: 100%;
  background: #888;
  height: 135px;
}

.imgNewsPreview {
  width: 215px;
  height: 135px;
  padding: 4px;
  float: left;
}

.newsHeaderPreview {
  color: #FFF;
  margin-top: 0px;
}

.newsBodyPreview {
  color: #FFF;
  margin-top: -12px;
}

.caption {
  color: #33CC33;
  text-align: center;
  position: absolute;
  font-size: 20px;
  width: 100%;
  padding: 8px 12px;
  bottom: 16px;
}

.collapsible {
  background: #888;
  color: #FFF;
  font-weight: bold;
  width: 100%;
  padding: 18px;
  cursor: pointer;
  font-size: 16px;
  outline: none;
  border: none;
  text-align: left;
}

.active,
.collapsible:hover {
  background: #666;
}

.collapsible:after {
  content: '\002B';
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 4px;
}

.active:after {
  content: '\2212';
}

.contentCollapsible {
  padding: 0px 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background: #F8F8F8;
}

.fade {
  -webkit-animation-name: fade;
  /* To work on Safari (Apple) */
  -webkit-animation-duration: 1s;
  /* To work on Safari (Apple) */
  animation-name: fade;
  animation-duration: 1s;
}

.buttonReturn {
  position: absolute;
  margin-left: 20px;
  margin-top: 20px;
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  font-size: 36px;
  text-align: center;
  border-radius: 50%;
  font-weight: bold;
}

.videoProp {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  height: 400px;
}

@-webkit-keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@media screen and (max-width: 600px) {
  /* Stacks navigation menu acting for the site to be responsive */
  .menuColumn {
    width: 100%;
    height: auto;
  }
}

@media screen and (max-width: 800px) {
  /* Stacks Image Header on Top - acting as responsive */
  .column,
  #column {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Responsive Sponser Images */
  .sponsers {
    width: 33.33%;
  }
}

@media screen and (max-width: 800px) {
  /* Increases video resolution as screen reduces */
  .videoProp {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Reduces font-size as screen resolution lowers */
  .newsBodyPreview {
    font-size: 14px;
  }
}

@media screen and (max-width: 300px) {
  /* Reduces font-sizes within the slideshow
 */
  .previous,
  .next,
  .caption {
    font-size: 14px;
  }
}

<!DOCTYPE HTML>

  <title>Contact Us — Macleay Netball Association</title>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0">
  <link rel="stylesheet" href="../style.css" type="text/css">

  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">

  <link rel="shortcut icon" href="../Assets/Img/mnaHeader.png">

        <button id="menuButton" title="Navigation Menu"> Menu</button>

               Home
               Association Contacts

               Weekly Draw
               News

               Quick Links
               Representative Teams

               Documentation
               Contact Us

1

2

Attached are some images if I put position:fixed bottom:0 in the #column CSS Code. Only Column 2 goes down, 1 is hidden.

Body:
Both 1 and 2 are fixed to the bottom. Only the float: left has no effect here and they are at the exactly same position. The 2 is in front of 1 and latter is not visible behind 2

Do this instead.

<div class="row footer">
  <div id="column">1</div>
  <div id="column">2</div>
</div>

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}

/* ~ Copyright (c) Macleay Netball Association (made by Tom Carpenter for Year 11 IPT Assessment Task #2.) 2019. */

html>body {
  background: none;
  padding: 0;
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Trebuchet MS', sans-serif;
  /* Trebuchet MS as main font throughout website, sans-serif acting as a backup */
}

#wrapper {
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  overflow: hidden;
  position: absolute;
  background: #1B315E;
}

::-webkit-scrollbar {
  display: none;
}

* {
  box-sizing: border-box;
  /* Alignment of DropDown Navigation Menu and Slideshow */
}

.navigation {
  background: #444;
  overflow: hidden;
  top: 0;
}

.menuDropDown {
  overflow: hidden;
  float: left;
}

.menuDropDown>#menuButton {
  font-size: 12px;
  padding: 16px 16px;
  /* Will result in final height of navigation */
  margin: 0;
  outline: none;
  border: none;
  font: inherit;
  background: inherit;
  color: #FFF;
}

#menuButton:hover,
.navigation>.menuDropDown:hover>#menuButton {
  border: none;
  outline: none;
  background: #666;
  color: #1B315E;
}

.menuDropDown:hover>.menuContent {
  display: block;
}

.menuContent {
  display: none;
  position: absolute;
  background: none;
  width: 100%;
  left: 0;
  max-height: 85vh;
  overflow: auto;
  box-shadow: 0px 8px 16px 0px rgba(0, 0, 0, 0.2);
  z-index: 1;
}

.menuRow:after {
  display: table;
  clear: both;
  content: "";
}

.menuColumn {
  width: 25%;
  height: 100px;
  overflow-y: auto;
  padding: 5px;
  float: left;
  background: #666;
}

.menuColumn>a {
  float: none;
  display: block;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
  padding: 8px;
  color: #1B315E;
}

.menuColumn>a.current {
  background: #777;
}

.menuColumn>a:hover {
  background: #888;
}

.logo {
  float: right;
  padding-right: 10px;
  width: 60px;
  height: 50px;
}

.main {
  width: 100%;
  height: calc(100vh - 43px);
  float: left;
  background: none;
  position: absolute;
  overflow: auto;
  padding: 8px;
}

.mainHeader {
  color: #FFF;
  text-align: center;
}

.mainImg {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
}

.mainBody {
  color: #FFF;
  padding: 8px;
}

.row:after {
  content: "";
  clear: both;
  display: table;
}

.column {
  float: left;
  width: 33.33%;
  padding: 8px;
}

#column {
  float: left;
  width: 50%;
  padding: 8px;
  background: #888;
  bottom: 0;
}

.sponsers {
  float: left;
  width: 20%;
  padding: 8px;
  -webkit-filter: grayscale(100%);
  filter: grayscale(100%);
}

.sponsers:hover {
  -webkit-filter: grayscale(80%);
  filter: grayscale(80%);
}

.slideshow {
  /* Slideshow Container containing Images, Sliders and Captions */
  position: relative;
  margin: auto;
  max-width: 1000px;
}

.slides {
  display: none;
}

.slideshowImages {
  width: 100%;
}

.slideButton {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  padding: 16px 32px;
  font-size: 18px;
  text-align: center;
  border-radius: 10px;
  font-weight: bold;
}

.mnaHeader {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  -ms-transform: translate(-50%, -50%);
}

.slideButton:hover {
  background: #666;
}

.previous,
.next {
  cursor: pointer;
  position: absolute;
  top: 50%;
  width: auto;
  margin-top: -22px;
  padding: 16px;
  color: #FFF;
  font-weight: bold;
  font-size: 18px;
  transition: 0.3s ease;
  border-radius: 0 3px 3px 0;
  user-select: none;
}

.next {
  right: 0;
  border-radius: 3px 0 0 3px;
}

.previous:hover,
.next:hover {
  background: rgba(0, 0, 0, 0.8);
}

table {
  width: 100%;
  font-size: 16px;
  color: #FFF;
}

.tableCaption {
  font-weight: bold;
  font-size: 18px;
  color: #33CC33;
}

table,
th,
td {
  border-collapse: collapse;
  border: 2px solid #888;
}

th,
td {
  padding: 8px;
  text-align: left;
}

#headerTable {
  width: 33.33%;
  background: #888;
  font-size: 18px;
  color: #33CC33;
}

.linkProp {
  color: #FFF;
  text-decoration: underline;
}

.newsPanel {
  width: 100%;
  background: #888;
  height: 135px;
}

.imgNewsPreview {
  width: 215px;
  height: 135px;
  padding: 4px;
  float: left;
}

.newsHeaderPreview {
  color: #FFF;
  margin-top: 0px;
}

.newsBodyPreview {
  color: #FFF;
  margin-top: -12px;
}

.caption {
  color: #33CC33;
  text-align: center;
  position: absolute;
  font-size: 20px;
  width: 100%;
  padding: 8px 12px;
  bottom: 16px;
}

.collapsible {
  background: #888;
  color: #FFF;
  font-weight: bold;
  width: 100%;
  padding: 18px;
  cursor: pointer;
  font-size: 16px;
  outline: none;
  border: none;
  text-align: left;
}

.active,
.collapsible:hover {
  background: #666;
}

.collapsible:after {
  content: '\002B';
  color: #FFF;
  font-weight: bold;
  float: right;
  margin-left: 4px;
}

.active:after {
  content: '\2212';
}

.contentCollapsible {
  padding: 0px 18px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.2s ease-out;
  background: #F8F8F8;
}

.fade {
  -webkit-animation-name: fade;
  /* To work on Safari (Apple) */
  -webkit-animation-duration: 1s;
  /* To work on Safari (Apple) */
  animation-name: fade;
  animation-duration: 1s;
}

.buttonReturn {
  position: absolute;
  margin-left: 20px;
  margin-top: 20px;
  background: #888;
  color: #FFF;
  border: none;
  cursor: pointer;
  font-size: 36px;
  text-align: center;
  border-radius: 50%;
  font-weight: bold;
}

.videoProp {
  display: block;
  margin-left: auto;
  margin-right: auto;
  width: 50%;
  height: 400px;
}

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
}
@-webkit-keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@keyframes fade {
  from {
    opacity: 0.4
  }
  to {
    opacity: 1
  }
}

@media screen and (max-width: 600px) {
  /* Stacks navigation menu acting for the site to be responsive */
  .menuColumn {
    width: 100%;
    height: auto;
  }
}

@media screen and (max-width: 800px) {
  /* Stacks Image Header on Top - acting as responsive */
  .column,
  #column {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Responsive Sponser Images */
  .sponsers {
    width: 33.33%;
  }
}

@media screen and (max-width: 800px) {
  /* Increases video resolution as screen reduces */
  .videoProp {
    width: 100%;
  }
}

@media screen and (max-width: 600px) {
  /* Reduces font-size as screen resolution lowers */
  .newsBodyPreview {
    font-size: 14px;
  }
}

@media screen and (max-width: 300px) {
  /* Reduces font-sizes within the slideshow <div> */
  .previous,
  .next,
  .caption {
    font-size: 14px;
  }
}

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
<div id="wrapper">
  <div class="navigation">
    <div class="menuDropDown">
      <button id="menuButton" title="Navigation Menu"><i class="fas fa-bars"></i> Menu</button>
      <div class="menuContent">
        <div class="menuRow">
          <div class="menuColumn">
            <a title="Home" href="../index.html"><i class="fas fa-home"></i> Home</a>
            <a title="Association Contacts" href="contacts.html"><i class="fas fa-address-book"></i> Association Contacts</a>
          </div>
          <div class="menuColumn">
            <a title="Weekly Draw" href="weekly-draw.html"><i class="fas fa-user-friends"></i> Weekly Draw</a>
            <a title="News" href="#"><i class="far fa-newspaper"></i> News</a>
          </div>
          <div class="menuColumn">
            <a title="Quick Links" href="links.html"><i class="fas fa-bookmark"></i> Quick Links</a>
            <a title="Representative Teams" href="representative-teams.html"><i class="fas fa-certificate"></i> Representative Teams</a>
          </div>
          <div class="menuColumn">
            <a title="Documentation" href="documentation.html"><i class="fas fa-file"></i> Documentation</a>
            <a class="current" title="Contact Us" href="contact-us.html"><i class="fas fa-phone"></i> Contact Us</a>
          </div>
        </div>
      </div>
    </div>
    <a href="../index.html"><img src="../Assets/Img/mnaHeader.png" alt="Macleay Netball Association" title="Macleay Netball Association" class="logo"></a>
    <!-- Macleay Netball Association Main Logo -->
  </div>
  <!-- End of Navigation -->
  <div class="main">
    <iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3417.0548484369647!2d152.83521681537312!3d-31.080401281517187!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x6b9ddf84d6da904b%3A0xfc941d1ded8f7a25!2sPam+Guyer+Netball+Centre!5e0!3m2!1sen!2sau!4v1559129788713!5m2!1sen!2sau"
      width="100%" height="400px" frameborder="0" style="border:0" allowfullscreen></iframe>
    <!-- Google Maps Embed -->
    <br>

    <div class="row footer">
      <div id="column">1</div>
      <div id="column">2</div>
    </div>
    <!-- End of Footer -->
  </div>
  <!-- End of Main -->
</div>
<!-- End of Wrapper -->


问:
Problems when creating a huge matrix
I am trying to create a kind of table with random characters and writing the into a file, but I have a problem. The problem appears when I want to create huge tables. For example for a table with 10 rows x 5 columns everything is perfect, but for a table with 1.000.000 rows and 100 columns I have errors. Do you have any idea how could I solvent this problem???

I attached you the code I have created:

```<code>#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<ctime>
#include<sstream>

using namespace std;

int main()
{
    int rows, columns, rowsMax, columnsMax;
    int element1;
    char word[10];

    cout<<"Write the number of rows of your table: ";
    cin>>rowsMax;

    cout<<"Write the number of columns of your table: ";
    cin>>columnsMax;

    string matriz[100000][5]; // Here I write the number of row and columns that must be the same than the numbers introduced as input

    string table ("Table1");

    ofstream myfile (table);
    if(myfile.is_open())
    srand(1);
    for(rows=0;rows<rowsMax;rows++)
    {
        for(columns=0;columns<columnsMax;columns++)
        {
            element1 = rand() % 100000 + 1;

            int len = rand () % 4 + 4;
            word [len] = 0;
            while (len) word [--len] = 'A' + rand () % 58;

            myfile<<element1<<word;
            myfile<<"|";

            std::stringstream ss;
            ss<<element1;

            string mat;
            mat +=ss.str();
            mat +=word;
            matriz[rows][columns]= mat;
        }
        myfile<<endl;

    }
    myfile.close();

    system("pause");
    return 0;

}
</code>```

Thanks in advance for all your help!

答:
A table with 1.000.000 rows and 100 columns:

```<code>string matriz[1000000][100];
</code>```

means 1000000*100*sizeof string >1MB , which is huge compared to the default thread stack size.
Even if you allocate the matrix using heap the size would be around more than 2GB ( default process Virtual memory).

Probably memory mapped mechanism would help!

Title: Problems when creating a huge matrix

Body:
I am trying to create a kind of table with random characters and writing the into a file, but I have a problem. The problem appears when I want to create huge tables. For example for a table with 10 rows x 5 columns everything is perfect, but for a table with 1.000.000 rows and 100 columns I have errors. Do you have any idea how could I solvent this problem???

I attached you the code I have created:

#include<iostream>
#include<fstream>
#include<stdio.h>
#include<string>
#include<ctime>
#include<sstream>

using namespace std;

int main()
{
    int rows, columns, rowsMax, columnsMax;
    int element1;
    char word[10];

    cout<<"Write the number of rows of your table: ";
    cin>>rowsMax;

    cout<<"Write the number of columns of your table: ";
    cin>>columnsMax;

    string matriz[100000][5]; // Here I write the number of row and columns that must be the same than the numbers introduced as input

    string table ("Table1");

    ofstream myfile (table);
    if(myfile.is_open())
    srand(1);
    for(rows=0;rows<rowsMax;rows++)
    {
        for(columns=0;columns<columnsMax;columns++)
        {
            element1 = rand() % 100000 + 1;

            int len = rand () % 4 + 4;
            word [len] = 0;
            while (len) word [--len] = 'A' + rand () % 58;

            myfile<<element1<<word;
            myfile<<"|";

            std::stringstream ss;
            ss<<element1;

            string mat;
            mat +=ss.str();
            mat +=word;
            matriz[rows][columns]= mat;
        }
        myfile<<endl;

    }
    myfile.close();

    system("pause");
    return 0;

}

Thanks in advance for all your help!

Body:
A table with 1.000.000 rows and 100 columns:

string matriz[1000000][100];

means 1000000*100*sizeof string >1MB , which is huge compared to the default thread stack size.
Even if you allocate the matrix using heap the size would be around more than 2GB ( default process Virtual memory).

Probably memory mapped mechanism would help!


问:
How to delete edittext dynamically everytime I click a button
I'm trying to add a new food with some add ons, basically everytime the add field button is press it will create two edittext which is the name and price of the add on, there will be a scenario whereby users wants to delete the edittext name and price. I've successfully created two edittexts also setting them with the IDs that i'm giving them in integer. But I'm having problem with deleting the two edittext with a button whenever i click the delete field button.

```<code>
// Add On
        addOnLayout.removeAllViews();
        addFields.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddOnCounters++;

                etFoodName = new EditText(addfoodAddOn.this);
                etFoodName.setId(ETFoodID);

                etFoodName.setHint("Enter your AddOn Name");

                etPrice = new EditText(addfoodAddOn.this);
                etPrice.setId(ETPriceID);
                etPrice.setHint("Enter your AddOn Price");

                Log.d("-------","-------------------what is edittext name id " + ETFoodID);
                Log.d("-------","-------------------what is edittext price id " + ETPriceID);

                ETFoodID++;
                ETPriceID++;

                addOnLayout.addView(etFoodName);
                addOnLayout.addView(etPrice);

            }
        });

        removeFields.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(AddOnCounters>=1 && ETFoodID > 0 && ETPriceID > 10){

                    addOnLayout.removeViewAt(ETFoodID);
                    addOnLayout.removeViewAt(ETPriceID);
                    ETFoodID--;
                    ETPriceID--;

                }
            }
        });
</code>```

I'm expecting the result to be whenever i click the delete field button, it will delete the very bottom last two edittexts which is the name and price.

答:
Replace your listener</p>

```<code>removeFields.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(AddOnCounters>=1 && ETFoodID > 0 && ETPriceID > 10){
                View v1 = addOnLayout.findViewById(ETFoodID);
                View v2 = addOnLayout.findViewById(ETPriceID);
                addOnLayout.removeView(v1);
                addOnLayout.removeView(v2);
                ETFoodID--;
                ETPriceID--;

            }
        }
    });
</code>```

Body:
I'm trying to add a new food with some add ons, basically everytime the add field button is press it will create two edittext which is the name and price of the add on, there will be a scenario whereby users wants to delete the edittext name and price. I've successfully created two edittexts also setting them with the IDs that i'm giving them in integer. But I'm having problem with deleting the two edittext with a button whenever i click the delete field button.

// Add On
        addOnLayout.removeAllViews();
        addFields.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AddOnCounters++;

                etFoodName = new EditText(addfoodAddOn.this);
                etFoodName.setId(ETFoodID);

                etFoodName.setHint("Enter your AddOn Name");

                etPrice = new EditText(addfoodAddOn.this);
                etPrice.setId(ETPriceID);
                etPrice.setHint("Enter your AddOn Price");

                Log.d("-------","-------------------what is edittext name id " + ETFoodID);
                Log.d("-------","-------------------what is edittext price id " + ETPriceID);

                ETFoodID++;
                ETPriceID++;

                addOnLayout.addView(etFoodName);
                addOnLayout.addView(etPrice);

            }
        });

        removeFields.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(AddOnCounters>=1 && ETFoodID > 0 && ETPriceID > 10){

                    addOnLayout.removeViewAt(ETFoodID);
                    addOnLayout.removeViewAt(ETPriceID);
                    ETFoodID--;
                    ETPriceID--;

                }
            }
        });

I'm expecting the result to be whenever i click the delete field button, it will delete the very bottom last two edittexts which is the name and price.

Body:
Replace your listener

removeFields.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(AddOnCounters>=1 && ETFoodID > 0 && ETPriceID > 10){
                View v1 = addOnLayout.findViewById(ETFoodID);
                View v2 = addOnLayout.findViewById(ETPriceID);
                addOnLayout.removeView(v1);
                addOnLayout.removeView(v2);
                ETFoodID--;
                ETPriceID--;

            }
        }
    });


问:
Writing a Factory method for STL random number generators
I'm trying to provide an interface — through a config file — for my users to choose a distribution for some of the parameters that they are using. I would like to use STL random number generator algorithms for this purpose.

Let's assume that my program reads a JSON from a command line. For the JSON provided below, the program needs to realize that it should generate a random number from the normal distribution with given mean and standard variation. (I'm using the same parameter names as STL library for clearance.)

```<code>{
    "dist": "normal_distribution",
    "mean": 0.1,
    "stddev": 0.5
}
</code>```

So far, I can parse the JSON easily, and use each distribution's param_type to initialize the distribution. I use the name to decide which distribution to decide the param_type and the distribution.

What I don't know is how to implement this nicely. I know that I should provide some sort of factory method for this, pass the JSON, and spit out a function or a class. If I want to return an instance of a class, let's say a unique_ptr of the generator, I need to define an abstract class, e.g., RandDist and write some sort of adaptor to incorporate my input, .... I generally don't need a lot from the class, just a gen() method should be enough.

I'm wondering if anyone have thoughts on this. Or, if anyone knows a library that can do this.

P.S. Input doesn't have to be a JSON object, any hash table would work per se.

答:
I've tried to keep the boilerplate to a bare minimum. Assumptions:

You know the type of your generator in advance (that's easily switchable if you need your generators to be dynamic as well)

All of the distributions generate doubles (that's pretty much baked in since the API has to return something concrete to be decently usable)

All of the distributions are constructible from double parameters (that's tweakable as well with a proxy object, but depending on your actual JSON library the work may already be done there)

I've used a GCC preprocessor extension to handle the zero-parameter case, but the macro can certainly be rewritten to not need it.

```<code>using Generator = std::mt19937;
using Distribution = std::function<double(Generator &)>;
using Json = std::map<std::string, std::string>;

template <class DistributionType, class... Parameters>
Distribution make_distribution_impl(Json const &json, Parameters... parameters) {
    return DistributionType{std::stod(json.at(parameters))...};
}

Distribution make_distribution(Json const &json) {
    auto const &distributionName = json.at("dist");

    #define generate_distribution_factory(name_, ...) \
        if(distributionName == #name_) \
            return make_distribution_impl<std::name_<double>>(json, ## __VA_ARGS__)

    generate_distribution_factory(uniform_real_distribution, "a", "b");
    generate_distribution_factory(normal_distribution, "mean", "stddev");
    // ...

    #undef generate_distribution_factory

    throw std::runtime_error{"Unknown distribution " + distributionName};
}
</code>```

See it live on Wandbox

Body:
I'm trying to provide an interface — through a config file — for my users to choose a distribution for some of the parameters that they are using. I would like to use STL random number generator algorithms for this purpose.

Let's assume that my program reads a JSON from a command line. For the JSON provided below, the program needs to realize that it should generate a random number from the normal distribution with given mean and standard variation. (I'm using the same parameter names as STL library for clearance.)

{
    "dist": "normal_distribution",
    "mean": 0.1,
    "stddev": 0.5
}

So far, I can parse the JSON easily, and use each distribution's param_type to initialize the distribution. I use the name to decide which distribution to decide the param_type and the distribution.

What I don't know is how to implement this nicely. I know that I should provide some sort of factory method for this, pass the JSON, and spit out a function or a class. If I want to return an instance of a class, let's say a unique_ptr of the generator, I need to define an abstract class, e.g., RandDist and write some sort of adaptor to incorporate my input, .... I generally don't need a lot from the class, just a gen() method should be enough.

I'm wondering if anyone have thoughts on this. Or, if anyone knows a library that can do this.

P.S. Input doesn't have to be a JSON object, any hash table would work per se.

Body:
I've tried to keep the boilerplate to a bare minimum. Assumptions:

You know the type of your generator in advance (that's easily switchable if you need your generators to be dynamic as well)

All of the distributions generate doubles (that's pretty much baked in since the API has to return something concrete to be decently usable)

All of the distributions are constructible from double parameters (that's tweakable as well with a proxy object, but depending on your actual JSON library the work may already be done there)

I've used a GCC preprocessor extension to handle the zero-parameter case, but the macro can certainly be rewritten to not need it.

using Generator = std::mt19937;
using Distribution = std::function<double(Generator &)>;
using Json = std::map<std::string, std::string>;

template <class DistributionType, class... Parameters>
Distribution make_distribution_impl(Json const &json, Parameters... parameters) {
    return DistributionType{std::stod(json.at(parameters))...};
}

Distribution make_distribution(Json const &json) {
    auto const &distributionName = json.at("dist");

    #define generate_distribution_factory(name_, ...) \
        if(distributionName == #name_) \
            return make_distribution_impl<std::name_<double>>(json, ## __VA_ARGS__)

    generate_distribution_factory(uniform_real_distribution, "a", "b");
    generate_distribution_factory(normal_distribution, "mean", "stddev");
    // ...

    #undef generate_distribution_factory

    throw std::runtime_error{"Unknown distribution " + distributionName};
}

See it live on Wandbox


答:
The best way to achieve this having responsiveness in mind and easier manipulation on different screen sizes is wrapping the two div elements in another div that you will position fixed on the bottom and then adjusting the two divs to take 50% of its parent. You've done half of this job by putting the divs into a .row wrapper.

The best solution would probably be using flex to adjust the divs in their parent wrapper like this:

Plus, you can not use the same id twice as it is in your example.

```<code><div class="row">
    <div>1</div>
    <div>2</div>
 </div>

<style>
    .row {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;

        display: flex;
    }
    .row > div {
        flex: 1;
    }
</style>
</code>```

Then on mobile devices you can just change the flex direction and the footer will become one-columned instead of two-columned. Like this:

```<code><style>
    @media only screen and (max-width: 768px) {
        .row {
            flex-direction: column;
        }
    }
</style>
</code>```

Title: How to keep div elements at bottom of page

Body:
The best way to achieve this having responsiveness in mind and easier manipulation on different screen sizes is wrapping the two div elements in another div that you will position fixed on the bottom and then adjusting the two divs to take 50% of its parent. You've done half of this job by putting the divs into a .row wrapper.

The best solution would probably be using flex to adjust the divs in their parent wrapper like this:

Plus, you can not use the same id twice as it is in your example.

<div class="row">
    <div>1</div>
    <div>2</div>
 </div>

<style>
    .row {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;

        display: flex;
    }
    .row > div {
        flex: 1;
    }
</style>

Then on mobile devices you can just change the flex direction and the footer will become one-columned instead of two-columned. Like this:

<style>
    @media only screen and (max-width: 768px) {
        .row {
            flex-direction: column;
        }
    }
</style>


问:
Missing assembly references
I have cleaned the solution. Even deleted contents of the bin folder. But I still get

Type or namespace name 'Mvc' does not exists in the namespace 'System.Web'

The type or namespace name 'Kendo' could not be found (are you missing a using directive or an assembly reference?)

How do I resolve this?

答:
You don't have the references needed.Install MVC, Kendo, etc. again and the references will be added to your project.

Either browse for the necessary packages (Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution) or install it using the Nuget console (Tools -> Nuget Package Manager -> Package Manager Console)

Title: Missing assembly references


问:
Printing Oracle Sys_refcursor in Oracle SQL Developer 1.5
I am trying to execute the procedure which returns a sys_refcursor as output. The procedure is   PROCEDURE GET_EMPLOYEEs(P_ID in NUMBER, P_OUT_CURSOR OUT SYS_REFCURSOR);

I wrote the below anonymous block in SQL Developer 1.5 and its executing fine,but when I try to print the cursor, I am getting an error. The cursor returns emp_name,salary and other columns.

```<code>set serveroutput on;
declare
result sys_refcursor;
begin
emp.emp360_utils.GET_EMPLOYEEs(222334,result);
dbms_output.put_line(result); // Error here
end;
</code>```

The error is

```<code>PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'
</code>```

UPDATED: Iterated for cursor,but still getting error as "Invalid reference to variable dummycursor".

```<code>    set serveroutput on;
    declare
    dummycursor sys_refcursor;
    result sys_refcursor;
    begin
     emp.emp360_utils.GET_EMPLOYEEs(222334,result);
    LOOP
    fetch result into dummycursor;
    EXIT when result%notfound;
    dbms_output.putline(dummycursor.lsn);
    end loop;
    end;
</code>```

答:
You can execute procedure using Run  button in package source

and view cursor content in tab Output variables

Body:
I am trying to execute the procedure which returns a sys_refcursor as output. The procedure is   PROCEDURE GET_EMPLOYEEs(P_ID in NUMBER, P_OUT_CURSOR OUT SYS_REFCURSOR);

I wrote the below anonymous block in SQL Developer 1.5 and its executing fine,but when I try to print the cursor, I am getting an error. The cursor returns emp_name,salary and other columns.

set serveroutput on;
declare
result sys_refcursor;
begin
emp.emp360_utils.GET_EMPLOYEEs(222334,result);
dbms_output.put_line(result); // Error here
end;

The error is

PLS-00306: wrong number or types of arguments in call to 'PUT_LINE'

UPDATED: Iterated for cursor,but still getting error as "Invalid reference to variable dummycursor".

    set serveroutput on;
    declare
    dummycursor sys_refcursor;
    result sys_refcursor;
    begin
     emp.emp360_utils.GET_EMPLOYEEs(222334,result);
    LOOP
    fetch result into dummycursor;
    EXIT when result%notfound;
    dbms_output.putline(dummycursor.lsn);
    end loop;
    end;


问:
How to set default value of ProductType attribute in Commercetools platform?
I wanna to set up default value if a ProductType attribute is empty or null.

This is the documentation I referred: https://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/meta/ProductAttributeDocumentation.html

答:
There is currently no default value that can be defined in product type attributes.

You could create a custom object for that purpose.

How do you plan to manage your product data?
Will you sync from an external system?


问:
Difference between [:,3] and [:,3:4] in python?
After importing dataset I see the different size of objects created by iloc when provided similar parameters.

I was trying to create a simple linear regression model.

```<code>y=dataset.iloc[:,3].values
z=dataset.iloc[:,3:4].values
</code>```

I expected y and z to be same but in variable explorer, size of y is (10,) and z is (10,1).
How do y and z get differentiated?

答: It is because when you put a single number it means a row or a column. However, if you put as a:b, it assumes it as a range, even if the number of elements is 1.

Body:
After importing dataset I see the different size of objects created by iloc when provided similar parameters.

I was trying to create a simple linear regression model.

y=dataset.iloc[:,3].values
z=dataset.iloc[:,3:4].values

I expected y and z to be same but in variable explorer, size of y is (10,) and z is (10,1).
How do y and z get differentiated?


问:
How do I parse Array within Array
I am trying to parse information that is inside an Array. The array comes from an RSS feed that I have converted into a json. The array is:

```<code><channel>
<item>
    <title> Title A </title>
    <description> Description A </description>
    <stuff url="google.com" type="search engine">
</item>

<item>
    <title> Title B </title>
    <description> Description B </description>
    <stuff url="yahoo.com" type="old stuff">
</item>
....

</channel>
</code>```

I am parsing using something like:

```<code>$newsoutput = json_decode(json_encode($the_RSS_Link), TRUE);

foreach ($newsoutput['channel']['item'] as $item) {
   echo $item['title'];
   echo "<br>";
   echo $item['description'];
   echo "<br>";
   echo $item['stuff']['url'];
   echo "<br>";
}
</code>```

I can get both "title" and "description"; but I cannot extract the "url" values inside "stuff". I have tried various combinations without luck

Please advise.

Thank you,

H.

答:
This is a tested and working example which requires the use of simplexml_load_string()

<?php
$raw = <<<XML
<?xml version='1.0'?>
<document>
    <channel>
        <item>
            <title>Title A</title>
            <description>Description A</description>
            <stuff url="google.com" type="search engine"></stuff>
        </item>

        <item>
            <title>Title B</title>
            <description>Description B</description>
            <stuff url="yahoo.com" type="old stuff"></stuff>
        </item>
    </channel>
</document>
XML;

$xml = simplexml_load_string($raw);
$newsoutput = json_decode(json_encode($xml), true);

foreach ($newsoutput['channel']['item'] as $item) {
    echo $item['title'];
    echo "
\n";
    echo $item['description'];
    echo "
\n";
    echo $item['stuff']['@attributes']['url'];
    echo "
\n";
}
```

<p>Output:</p>

```Title A

Description A

google.com

Title B

Description B

yahoo.com

```

Be careful, the XML document you gave us was invalid and I had to close the  tag.

Title: How do I parse Array within Array

Body:
I am trying to parse information that is inside an Array. The array comes from an RSS feed that I have converted into a json. The array is:

<channel>
<item>
    <title> Title A </title>
    <description> Description A </description>
    <stuff url="google.com" type="search engine">
</item>

<item>
    <title> Title B </title>
    <description> Description B </description>
    <stuff url="yahoo.com" type="old stuff">
</item>
....

</channel>

I am parsing using something like:

$newsoutput = json_decode(json_encode($the_RSS_Link), TRUE);

foreach ($newsoutput['channel']['item'] as $item) {
   echo $item['title'];
   echo "
";
   echo $item['description'];
   echo "
";
   echo $item['stuff']['url'];
   echo "
";
}

I can get both "title" and "description"; but I cannot extract the "url" values inside "stuff". I have tried various combinations without luck

Please advise.

Thank you,

H.

Body:
This is a tested and working example which requires the use of simplexml_load_string()

<?php
$raw = <<<XML
<?xml version='1.0'?>
<document>
    <channel>
        <item>
            <title>Title A</title>
            <description>Description A</description>
            <stuff url="google.com" type="search engine"></stuff>
        </item>

        <item>
            <title>Title B</title>
            <description>Description B</description>
            <stuff url="yahoo.com" type="old stuff"></stuff>
        </item>
    </channel>
</document>
XML;

$xml = simplexml_load_string($raw);
$newsoutput = json_decode(json_encode($xml), true);

foreach ($newsoutput['channel']['item'] as $item) {
    echo $item['title'];
    echo "<br>\n";
    echo $item['description'];
    echo "<br>\n";
    echo $item['stuff']['@attributes']['url'];
    echo "<br>\n";
}

Output:

Title A<br>
Description A<br>
google.com<br>
Title B<br>
Description B<br>
yahoo.com<br>

Be careful, the XML document you gave us was invalid and I had to close the  tag.


问:
How to change structure of list items with JS to solve inline-block's generated space between them
In some of the ways to remove the space between list items when using inline-block, a way is to change this code:

ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul></code>```

to this code:

ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><ul><li>
    Item 1</li><li>
    Item 2</li><li>
    Item 3</li>
</ul></code>```

which works perfectly fine.

The question is how to change the first code's li structure to second code's using pure Javascript.

答:
You could do something like this:

const ul = document.querySelector('ul');
const iterator = document.createNodeIterator(ul, NodeFilter.SHOW_TEXT, node => {
  if (node.parentElement.nodeName === 'UL') {
    return NodeFilter.FILTER_ACCEPT;
  }
  return NodeFilter.FILTER_REJECT;
});

const toBeRemoved = [];
let next = iterator.nextNode();
while(next) {
  toBeRemoved.push(next);
  next = iterator.nextNode();
}

toBeRemoved.forEach(n => n.remove());```
<pre class="snippet-code-css lang-css prettyprint-override"><code>ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}</code>```

Item 1

Item 2

Item 3

```

What this does is to create a NodeIterator to iterate over all the text nodes of the UL element and keep only those nodes that have the UL as their first ancestor.

Body:
In some of the ways to remove the space between list items when using inline-block, a way is to change this code:

ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}

Item 1

Item 2

Item 3

to this code:

ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}

    Item 1

    Item 2

    Item 3

which works perfectly fine.

The question is how to change the first code's li structure to second code's using pure Javascript.

Body:
You could do something like this:

const ul = document.querySelector('ul');
const iterator = document.createNodeIterator(ul, NodeFilter.SHOW_TEXT, node => {
  if (node.parentElement.nodeName === 'UL') {
    return NodeFilter.FILTER_ACCEPT;
  }
  return NodeFilter.FILTER_REJECT;
});

const toBeRemoved = [];
let next = iterator.nextNode();
while(next) {
  toBeRemoved.push(next);
  next = iterator.nextNode();
}

toBeRemoved.forEach(n => n.remove());

ul{
  width: 100%;
  padding: 0;
  margin: 0;
}
li{
  display: inline-block;
  background: #E43;
  color: white;
  padding: 10px 20px 10px 20px;
}
li:hover{
  background: #F65;
  border-bottom: 2px solid dodgerblue;
}

<ul>
    <li>Item 1</li>
    <li>Item 2</li>
    <li>Item 3</li>
</ul>

What this does is to create a NodeIterator to iterate over all the text nodes of the UL element and keep only those nodes that have the UL as their first ancestor.


问:
Zero an array in C code

Possible Duplicates:

  How to initialize an array to something in C without a loop?

  How to initialize an array in C

How can I zero a known size of an array without using a for or any other loop ?

For example:

```<code>arr[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
</code>```

This is the long way... I need it the short way.

答:
```<code>int arr[20];
memset(arr, 0, sizeof arr);
</code>```

See the reference for memset

Title: Zero an array in C code

Body:
Possible Duplicates:

  How to initialize an array to something in C without a loop?

  How to initialize an array in C

How can I zero a known size of an array without using a for or any other loop ?

For example:

arr[20] = 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;

This is the long way... I need it the short way.

Body:
int arr[20];
memset(arr, 0, sizeof arr);

See the reference for memset