<ViewStub
android:id="@+id/lazy_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
ViewStub lazyLayout = (ViewStub) findViewById(R.id.lazy_layout);
lazyLayout.setLayoutResource(R.layout.main_activity_body); // Либо R.layout.second_activity_body
lazyLayout.inflate();
public static final String HOST = "api.site.com";
$.ajax({
url: this.url + this.currentPage,
type: `GET`,
/*... more params */
}).done(this.onRequest);
$.ajax({
url: this.url + this.currentPage,
type: `GET`,
/*... more params */
}).done(data => this.onRequest(data))
SystemJS.config({
"defaultJSExtensions": true,
map: {
css: '/js/system-css.js',
datepicker: 'js/datepicker.js'
},
meta: {
'*.css': { loader: 'css' }
},
baseURL: '/',
paths: {
jquery: 'js/jquery',
scrollbar: 'js/scrollbar'
}
});
interface DoRequestInterface {
void execute(String url, DoRequesCallback callback);
}
interface DoRequesCallback {
void successReq(JSONObject response);
void errorReq(VolleyError error);
}
public abstract class DoRequestClass implements DoRequestInterface {
@Override
public void execute(String url, DoRequesCallback callback) {
RequestQueue queue = Volley.newRequestQueue(context);
final WeakReference<DoRequesCallback> weakCallback = new WeakReference<DoRequesCallback>(callback);
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
DoRequesCallback callback = weakCallback.get();
if (callback != null) {
callback.successReq(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
DoRequesCallback callback = weakCallback.get();
if (callback != null) {
callback.errorReq(error);
}
}
});
queue.add(jsObjRequest);
}
}
public class MainActivity extends AppCompatActivity implements DoRequesCallback {
@Override
protected void onCreate(Bundle savedInstanceState) {
sendButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DoRequestClass doRequestClass = new DoRequestClass();
doRequestClass.execute("http://myserver.local", this);
}
});
}
@Override
public void successReq(JSONObject response){
txtDisplay.setText("Response => "+response.toString());
}
@Override
public void errorReq(VolleyError error){
txtDisplay.setText("Error => "+error.toString());
}
}
if (rooms.length) {
/*...*/
} else {
for (var id in self.sids) {
/*...*/
}
}