In my MainActivity.java i have set some text to a TextView, how do I get the text that I had set to the TextView
My Textview -
<TextView
android:id="@+id/show"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="visible" />
ASyncTask -
public class fetchdata extends AsyncTask<Void, Void, Void> {
private String data = "";
@Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL("https://blablabla.com/hello.json");
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
data = bufferedReader.readLine();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity.show.setText(this.data);
}
}
MainActivity -
private static TextView show;
...... show is static
show = findViewById(R.id.show);
String data = show.getText().toString();
but data is empty instead of me getting "this is the text I want to get"