3
I am passing a value to a textview, but that do so after my variable receives this value.
public class ariesFragment extends Fragment
{
public String[]textoSeparado2;
public ariesFragment()
{
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
//executando MyAsyncTask
MyAsyncTask myAsyncTask = new MyAsyncTask();
myAsyncTask.execute();
View view = inflater.inflate(R.layout.fragment_aries, container, false);
TextView text = (TextView)view.findViewById(R.id.textAries);
if(textoSeparado2 == null)
{
text.setText("ERROR VOCÊ NÃO TEM UMA CONEXÃO COM A INTERNET");
System.out.println("erro");
}
else
{
text.setText(textoSeparado2[5]);
}
return view;
}
private class MyAsyncTask extends AsyncTask
{
@Override
protected Object doInBackground(Object[] params)
{
HttpURLConnection conection;
try
{
//Configuração de conexao
URL url = new URL("http://meusite");
conection = (HttpURLConnection) url.openConnection();
conection.connect();
// Lendo os dados
InputStream inputStream = conection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
StringBuffer stringBuffer = new StringBuffer();
//Storing data
String line = new String();
while ((line = bufferedReader.readLine())!= null)
{
textoSeparado2 = line.split("\\|");
System.out.println(textoSeparado2[0]);
//System.out.println(line);
}
//Close Conection
inputStream.close();
conection.disconnect();
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Object o)
{
super.onPostExecute(o);
}
}
}
It searches the php file on the internet, but when it checks if my array is null, it says yes, because I still have no values in it and only then will receive.
How do I pass the value to the textview
after searching the php file?
I tried so many ways and I couldn’t
View view = inflater.inflate(R.layout.fragment_aries, container, false);
TextView text = (TextView)view.findViewById(R.id.textAries);
Using this I can pass to textview.
Thank you in advance
I didn’t understand how to do it, I did it this way and I have many mistakes... mainly in the creation of the method for text view
– user46736