我会通过json将“jsonlist”(ArrayList <HashMap <String, String >>
)传递给php。
任何人都可以帮助我吗?
package ctb.manutenzione;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ctb.manutenzione.library.JSONParser;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
public class ManutenzioneGiornaliera extends ListActivity {
private static final String Campo1 = "phpCampo1";
private static final String Campo2 = "phpCampo2";
public String percorsoPHP;
String url;
ArrayList<HashMap<String, String>> jsonlist = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_manutenzionegiornaliera);
url= ("http://192.0.0.1/ctb/mangiornaliera.php");
Button startBtn = (Button) findViewById(R.id.inviamanutenzione);
startBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//todo
}
});
new ProgressTask(ManutenzioneGiornaliera.this).execute();
}
public class ProgressTask extends AsyncTask<String, Void, Boolean> {
private ProgressDialog dialog;
// private List<Message> messages;
public ProgressTask(ListActivity activity) {
context = activity;
dialog = new ProgressDialog(context);
}
private Context context;
protected void onPreExecute() {
this.dialog.setMessage("Progress start");
this.dialog.show();
}
@Override
protected void onPostExecute(final Boolean success) {
if (dialog.isShowing()) {
dialog.dismiss();
}
ListAdapter adapter = new SimpleAdapter(
context,
jsonlist,
R.layout.activity_manutenzionegiornaliera_row,
new String[]{Campo1,
Campo2},
new int[]{R.id.Campo1,
R.id.Campo2}
);
setListAdapter(adapter);
}
protected Boolean doInBackground(final String... args) {
jsonlist.clear();
JSONParser sitoLogin = new JSONParser();
String[] params = new String[1];
JSONArray json;
try {
json = sitoLogin.getJSONFromUrl5(url, params);
for (int i = 0; i < json.length(); i++) {
try {
JSONObject c = json.getJSONObject(i);
String campo1 = c.getString(Campo1);
String campo2 = c.getString(Campo2);
HashMap<String, String> map = new HashMap<String, String>();
// Add child node to HashMap key & value
map.put(Campo1, campo1);
map.put(Campo2, campo2);
jsonlist.add(map);
}
catch (JSONException e) {
e.printStackTrace();
}
}
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return null;
}
}
}
从json = sitoLogin.getJSONFromUrl5(url, params);
我得到一些来自php的查询返回的记录