如何在发出获取请求之前使用 (key,value) 对附加 URL
我
restaurant name
从以前的活动中 经过Intents
我将该值存储在变量中
restaurant_name
现在如何在发出获取请求之前将存储在变量restaurant_name
中的值url
作为(键,值)传递给
餐厅desc.java
public class RestaurantDesc extends Activity{
// url to make request
private static String url = "http://***********************";
String restaurant_name ;
ProgressDialog progressDialog;
JSONObject jsonObject;
JSONArray first_array ;
JSONArray second_array;
TextView textView;
TextView text;
TextView topdisp;
private SparseArray<String> startarsMap = new SparseArray<String>();
private SparseArray<String> saladsMap = new SparseArray<String>();
private SparseArray<String> maincourseMap = new SparseArray<String>();
private SparseArray<String> desertMap = new SparseArray<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.restaurant_desc);
//url = getIntent().getStringExtra("key");
restaurant_name = getIntent().getStringExtra("key");
topdisp=(TextView) findViewById(R.id.TopNavigationBarRestaurantDescActivityName);
Button BACKBUTTON=(Button) findViewById(R.id.TopNavigationBarRestaurantDescActivityBackButton);
BACKBUTTON.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent emp1=new Intent(RestaurantDesc.this,MainActivity.class);
startActivity(emp1);
}
});
Button PHOTOBUTTON=(Button) findViewById(R.id.RestaurantPhotosButton);
PHOTOBUTTON.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent pht=new Intent(RestaurantDesc.this,RestaurantPhotos.class);
pht.putExtra("key", getIntent().getStringExtra("key"));
startActivity(pht);
}
});
progressDialog=new ProgressDialog(RestaurantDesc.this);
new ParsingAsync().execute();
}
private class ParsingAsync extends AsyncTask<Void, Void, Void>
{
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog=ProgressDialog.show(RestaurantDesc.this, "", "Please Wait", true, false);
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
String _response = null;
try
{
HttpClient httpclient = new DefaultHttpClient();
httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
//url = url."?Key=restaurant_name";
//url += "?" + "key=" + restaurant_name;
HttpGet request = new HttpGet(url=url += "?" + "Key=" + restaurant_name);
HttpResponse response = httpclient.execute(request);
HttpEntity resEntity = response.getEntity();
_response =EntityUtils.toString(resEntity);
jsonObject = new JSONObject(_response);
first_array = jsonObject.getJSONArray("RestaurantNAME");
<-------------------- 其余代码------------------------> }