Lists, counters, and refs

I'm trying to create an environment containing a single-instance, numbered list (so that I can easily control the spacing, etc.). The problem is that I cannot used \ref to cross-ref to the enumerated item.

The code of a MWE is:

\documentclass{article}
\newcounter{tesisc}
\AtBeginDocument{\setcounter{tesisc}{1}}
\newenvironment*{Tesis}
{\begin{list}
{$(\arabic{tesisc})$}
{\setlength{\rightmargin}{0cm}
\setlength{\leftmargin}{2\parindent}}
\item
}
{\end{list}\refstepcounter{tesisc}}
\begin{document}
\begin{Tesis}
Testing testing testing testing testing testing testing testing testing testing.
\label{th:one}
\end{Tesis}
\begin{Tesis}
Testing testing testing testing testing testing testing testing testing testing.
\label{th:two}
\end{Tesis}
This is one reference: \ref{th:one}. This is another reference: \ref{th:two}.
\end{document}


My environment numbering works fine, but not the cross-referencing.

How can I tweak my definition in order for my references work?

-

You need to move the \refstepcounter earlier, or as here use \usecounter so list sets up \item to increment the counter.

\documentclass{article}
\newcounter{tesisc}

\newenvironment*{Tesis}
{\begin{list}
{$(\arabic{tesisc})$}
{\setlength{\rightmargin}{0cm}
\refstepcounter{tesisc}\setlength{\leftmargin}{2\parindent}}
\item
}
{\end{list}}
\begin{document}
\begin{Tesis}
Testing testing testing testing testing testing testing testing testing testing.
\label{th:one}
\end{Tesis}
\begin{Tesis}
Testing testing testing testing testing testing testing testing testing testing.
\label{th:two}
\end{Tesis}
This is one reference: \ref{th:one}. This is another reference: \ref{th:two}.
\end{document}

-
My comment was just earlier by 1 second. Need to delete that now :) – hpesoj626 Dec 24 '12 at 1:06
Great! But why just moving \refstepcounter does the trick? – NVaughan Dec 24 '12 at 1:15
It is refstepcounter that sets up the context that \label saves to the aux file, so if you do it in the end code it's too late. – David Carlisle Dec 24 '12 at 1:18