public class MobileActivity extends Activity {
ArrayList<Actors> actorsList;
public String latti;
public String longi;
ActorAdapter adapter;
JSONParser jParser = new JSONParser();
private static String url_search = "http://10.0.2.2/AndroidApp/mobile1.php";
//String url_search = "http://10.0.2.2/AndroidApp/mobile1.php?lat="+lat+"&lon="+lon;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.offer_activity);
actorsList = new ArrayList<Actors>();
new JSONAsyncTask().execute(url_search);
final ListView listview = (ListView)findViewById(R.id.list);
adapter = new ActorAdapter(getApplicationContext(), R.layout.icons, actorsList);
listview.setAdapter(adapter);
Intent myIntent = getIntent();
latti = myIntent.getStringExtra("lat");
longi = myIntent.getStringExtra("lon");
//Toast.makeText(this, latti, Toast.LENGTH_LONG).show();
//Toast.makeText(this, longi, Toast.LENGTH_LONG).show();
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position,
long id) {
// TODO Auto-generated method stub
//Toast.makeText(getApplicationContext(), actorsList.get(position).getId(), Toast.LENGTH_LONG).show();
String pid=actorsList.get(position).getName();
Intent intent = new Intent(MobileActivity.this,ProductDetails.class);
intent.putExtra("keyid",pid.toString());
startActivity(intent);
//initiatePopupWindow();
/* LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popup, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
btnDismiss.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}});
popupWindow.showAsDropDown(listview, 10, -400);
}*/}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main_actions, menu);
android.app.ActionBar bar = getActionBar();
bar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#20B2AA")));
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Take appropriate action for each action item click
switch (item.getItemId()) {
case R.id.hom:
Intent hom = new Intent(this, OpenApp.class);
startActivity(hom);
return true;
case R.id.grid:
// search action
Intent searchIntent1 = new Intent(this, MobileGrid.class);
searchIntent1.putExtra("lat",latti.toString());
searchIntent1.putExtra("lon",longi.toString());
startActivity(searchIntent1);
return true;
default:
return super.onOptionsItemSelected(item);
}
}
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
ProgressDialog dialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
dialog = new ProgressDialog(MobileActivity.this);
dialog.setMessage("Loading, please wait");
dialog.setTitle("Connecting server");
dialog.show();
dialog.setCancelable(false);
}
@Override
protected Boolean doInBackground(String... urls) {
try {
//------------------>>
List<NameValuePair> params = new ArrayList<NameValuePair>(2);
params.add(new BasicNameValuePair("lat", latti));
params.add(new BasicNameValuePair("lon", longi));
//HttpGet httppost = new HttpGet(urls[0]);
//HttpClient httpclient = new DefaultHttpClient();
//HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
//int status = response.getStatusLine().getStatusCode();
//if (status == 200) {
//HttpEntity entity = response.getEntity();
//String data = EntityUtils.toString(entity);
JSONObject jsono = jParser.makeHttpRequest(url_search, "GET",params);
//JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("offer_reg");
for (int i = 0; i < jarray.length(); i++) {
JSONObject object = jarray.getJSONObject(i);
Actors actor = new Actors();
actor.setName(object.getString("offer_id"));
actor.setDescription(object.getString("lat"));
//actor.setDob(object.getString("dob"));
actor.setCountry(object.getString("log"));
//actor.setHeight(object.getString("tag3"));
//actor.setSpouse(object.getString("tag4"));
//actor.setChildren(object.getString("tag1"));
actor.setImage(object.getString("offer_image"));
actorsList.add(actor);
}
return true;
//}
//------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
dialog.cancel();
adapter.notifyDataSetChanged();
if(result == false)
Toast.makeText(getApplicationContext(), "Unable to fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
无法从android中的服务器(PHP,mysql)获取数据,使用lattitude和longitude获取图像视图...显示某些时间图像视图...有时无法从服务器获取数据