I'm trying to use some methods of an Activity in a Fragment, but I can not, can someone tell me if it's possible?
public class updateMarker extends Activity {
TextView uid;
//URL to get JSON Array
private static String url = "http://t4web.hospedagemdesites.ws/alarme/update.php";
//JSON Node Names
private static final String TAG_USER = "markers";
private static final String TAG_ID = "id";
JSONArray markers = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.teste);
new JSONParse().execute();
}
public class JSONParse extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
@Override
public void onPreExecute() {
super.onPreExecute();
uid = (TextView)findViewById(R.id.uid);
pDialog = new ProgressDialog(updateMarker.this);
pDialog.setMessage("Carregando..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONObject json = jParser.getJSONFromUrl(url);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
pDialog.dismiss();
try {
// Getting JSON Array
markers = json.getJSONArray(TAG_USER);
JSONObject c = markers.getJSONObject(0);
// Storing JSON item in a Variable
String id = c.getString(TAG_ID);
//Set JSON Data in TextView
uid.setText(id);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
I intend to use all methods of this class in this Fragment:
public class UpdatesFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.updates_layout, null);
}
}
Does anyone know if it's possible? If so, how?