you are correct that the null hypothesis $H_0$ must be set (fixed, chosen) before sampling. You should write it down early in the process.
Only then do you get a sample, and look at your random sample.
Then, the p-value of your test is the probability of seeing what you see, under the assumption that $H_0$ is true.
For example, I have a bag of 100 marbles. Each one is either red or green. Write down:
$$H_0:\,\,\text{exactly half of the marbles are red.}$$
$$H_a:\,\,\text{more than half of the marbles are red.}$$
Then sample with replacement. (with replacement so the calculation is easier.) Why not $n=3$.
Resulting sample: RED, RED, RED. This is what we see, what we observe.
The probability of seeing this (if $H_0$ is true and if the sampling is really random) is $0.125.$
So the p-value of this test for this sample is the number $0.125$.
Note $0.125$ is not $P(\text{alternative hypothesis is true})$, and it is not so clear that $P(\text{alternative hypothesis is true})$ has any meaning.
But $0.125$ is a number that summarizes the evidence from our sample. In fact, the smaller the number, the more we are open to the idea that the alternative is true. In other words, a small p-value makes us doubt the null hypothesis.
By the way, in my bag are 100 red marbles. So you see how $0.125$ is a hypothetical probability.
p.s. I do not think having the null and alternative hypotheses simultaneously possible is a good idea. I cannot at the moment think of any example where they fail to be mutually exclusive.
p.p.s. I cheated you not a little bit in the above. The truth is, the p-value of your test and sample is the probability of seeing what you see, OR of seeing something equally surprising, OR of seeing something even more surprising. And how to understand 'more surprising'? This means possible samples which are more consistent with $H_a$ than our actual sample, when assuming a world in which $H_0$ is really true.
This is tougher to understand.
To test yourself, use this idea to find the p-value for the sample: RED, RED, GREEN. (now using a new bag #2 of 100 mystery marbles, each either red or green.)
Another self-test: convince yourself that $0.125$ is still correct above, using this real, more complicated definition of p-value.