這是我的延伸按鈕class`上下文在擴展按鈕類中是什麼意思? Context的默認值是什麼?
import android.content.Context;
import android.widget.Button;
public class Hotel extends Button{
String id;
String name;
String company_id;
public Hotel(Context context, String id, String name, String company_id) {
super(context);
this.id = id;
this.name = name;
this.company_id = company_id;
}
}
什麼是語境在擴展按鈕類建設淺析參數?
我想用這個類作爲另一個類中的數組,但我不知道我應該在上下文中寫什麼? İamtring從肥皂服務獲取酒店按鈕並使用下面的代碼。這個GetHotels方法在另一個類中。我只是對上下文事物感到困惑。請幫幫我。
import android.content.Context;
import org.json.JSONArray;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapPrimitive;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
/**
* Created by arzucaki on 09/05/2017.
*/
public class ServiceManager {
private static final String METHOD_NAME = "GetHotels";
private static final String NAMESPACE = "http://tempuri.org/";
private static final String SOAP_ACTION = "http://tempuri.org/GetHotels";
private static final String URL = "http://192.168.1.170/HotelApps_WebServices.asmx";
public static Context mContext;
SoapObject soapObject;
SoapSerializationEnvelope soapSerializationEnvelope;
HttpTransportSE httpTransportSE;
public Hotel[] GetHotels(int Company_id) {
soapObject = new SoapObject(NAMESPACE, METHOD_NAME);
soapObject.addProperty("Company_id", Company_id);
soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.dotNet = true;
soapSerializationEnvelope.setOutputSoapObject(soapObject);
httpTransportSE = new HttpTransportSE(URL);
httpTransportSE.debug = true;
Hotel hotels[]=new Hotel[6];
try {
httpTransportSE.call(SOAP_ACTION, soapSerializationEnvelope);
SoapPrimitive soapPrimitive=(SoapPrimitive)soapSerializationEnvelope.getResponse();
JSONArray jsonHotels = new JSONArray(soapPrimitive.toString());
for (int i=0; i<6; i++) {
hotels[i]=new Hotel(mContext, jsonHotels.getJSONObject(i).getString("Hotel_id"),jsonHotels.getJSONObject(i).getString("Hotel_Name"), jsonHotels.getJSONObject(i).getString("Company_id"));
}
return hotels;
} catch (Exception ex) {
ex.printStackTrace();
return hotels;
}
}
}
我打電話的方法就在這裏
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.GridLayout;
public class Hotels extends AppCompatActivity {
ServiceManager service=new ServiceManager();;
Hotel hotels[];
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hotels);
GridLayout glHotels=(GridLayout) findViewById(R.id.glHotels);
Thread getHotels=new Thread(new Runnable() {
@Override
public void run() {
hotels=service.GetHotels(1);
}
});
getHotels.start();
for (int i=0; i<hotels.length; i++) {
glHotels.addView(hotels[i]);
}
}
}
pass getApplica tionContext()作爲上下文中的參數 –
你是什麼意思? – arzucaki
我的意思是:酒店酒店=新酒店(getApplicationContext(),......) –