Php “我的活动”页面中不会显示任何结果
我的问题是我不能在我的活动页面中看到我的数据,但我可以在日志cat中看到它 11-01 03:14:25.295:D/所有产品:(11015):{“成功”:1,“scb”:[{“id”:“14”,“title”:“test1”},{“id”:“15”,“title”:“title”},{“id”:“16”,“title”:“title”},{“id”:“17”,“title”:“we”} 我的php文件很好,我知道这是因为我对它们进行了测试Php “我的活动”页面中不会显示任何结果,php,android,xml,android-activity,Php,Android,Xml,Android Activity,我的问题是我不能在我的活动页面中看到我的数据,但我可以在日志cat中看到它 11-01 03:14:25.295:D/所有产品:(11015):{“成功”:1,“scb”:[{“id”:“14”,“title”:“test1”},{“id”:“15”,“title”:“title”},{“id”:“16”,“title”:“title”},{“id”:“17”,“title”:“we”} 我的php文件很好,我知道这是因为我对它们进行了测试 package com.example.stu
package com.example.studentcookbook;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.http.NameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
//import com.example.androidhive.AllProductsActivity;
//import com.example.androidhive.EditProductActivity;
//import com.example.androidhive.NewProductActivity;
//import com.example.androidhive.R;
//import com.example.androidhive.AllProductsActivity.LoadAllProducts;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class GetAllRecipesActivity extends ListActivity {
// Progress Dialog
private ProgressDialog pDialog;
// Creating JSON Parser object
JSONParser jParser = new JSONParser();
ArrayList<HashMap<String, String>> productsList;
// url to get all products list
private static String url_all_products = "http://studentcookbook.comoj.com/android_connect/get_all_products.php";
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "products";
private static final String TAG_SCB_ID = "id";
private static final String TAG_TITLE = "title";
// products JSONArray
JSONArray products = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_get_all_recipes);
// Hashmap for ListView
productsList = new ArrayList<HashMap<String, String>>();
// Loading products in Background Thread
new LoadAllProducts().execute();
// Get listview
ListView lv = getListView();
// on seleting single product
// launching Edit Product Screen
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String pid = ((TextView) view.findViewById(R.id.GetAllscbid)).getText().toString();
// Starting new intent
Intent in = new Intent(getApplicationContext(),EditRecipeActivity.class);
// sending pid to next activity
in.putExtra(TAG_SCB_ID, pid);
// starting new activity and expecting some response back
startActivityForResult(in, 100);
}
});
}//end onCreate method
// Response from Edit Product Activity
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}
}
/**
* Background Async Task to Load all product by making HTTP Request
* */
class LoadAllProducts extends AsyncTask<String, String, String> {
/**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(GetAllRecipesActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}
/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
// Check your log cat for JSON reponse
Log.d("All Products: ", json.toString());
try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// products found
// Getting Array of Products
products = json.getJSONArray(TAG_PRODUCTS);
// looping through All Products
for (int i = 0; i < products.length(); i++) {
JSONObject c = products.getJSONObject(i);
// Storing each json item in variable
String id = c.getString(TAG_SCB_ID);
String name = c.getString(TAG_TITLE);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_SCB_ID, id);
map.put(TAG_TITLE, name);
// adding HashList to ArrayList
productsList.add(map);
}
} else {
// no products found
// Launch Add New product Activity
Intent i = new Intent(getApplicationContext(),AddRecipeActivity.class);
// Closing all previous activities
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* After completing background task Dismiss the progress dialog
* **/
protected void onPostExecute(String file_url) {
// dismiss the dialog after getting all products
pDialog.dismiss();
// updating UI from Background Thread
runOnUiThread(new Runnable() {
public void run() {
/**
* Updating parsed JSON data into ListView
* */
ListAdapter adapter = new SimpleAdapter(GetAllRecipesActivity.this, productsList,
R.layout.list_recipe, new String[] { TAG_SCB_ID,TAG_TITLE},
new int[] { R.id.GetAllscbid, R.id.GetAllTitle });
// updating listview
Toast.makeText(GetAllRecipesActivity.this, "onPostExecute", Toast.LENGTH_SHORT).show();
setListAdapter(adapter);
}
});
}
}
}//end GetAllRecipesActivity class
package.com.example.studentcookbook;
导入java.util.ArrayList;
导入java.util.HashMap;
导入java.util.List;
导入org.apache.http.NameValuePair;
导入org.json.JSONArray;
导入org.json.JSONException;
导入org.json.JSONObject;
//导入com.example.androidhive.AllProductsActivity;
//导入com.example.androidhive.EditProductActivity;
//导入com.example.androidhive.NewProductActivity;
//导入com.example.androidhive.R;
//导入com.example.androidhive.AllProductsActivity.LoadAllProducts;
导入android.app.Activity;
导入android.app.ListActivity;
导入android.app.ProgressDialog;
导入android.content.Intent;
导入android.os.AsyncTask;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.Menu;
导入android.view.MenuItem;
导入android.view.view;
导入android.widget.AdapterView;
导入android.widget.ListAdapter;
导入android.widget.ListView;
导入android.widget.simpledapter;
导入android.widget.TextView;
导入android.widget.Toast;
导入android.widget.AdapterView.OnItemClickListener;
公共类GetAllRecipesActivity扩展了ListActivity{
//进度对话框
私人对话;
//创建JSON解析器对象
JSONParser jParser=新的JSONParser();
ArrayList productsList;
//获取所有产品列表的url
私有静态字符串url\u所有产品=”http://studentcookbook.comoj.com/android_connect/get_all_products.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串TAG_PRODUCTS=“PRODUCTS”;
私有静态最终字符串标记\u SCB\u ID=“ID”;
私有静态最终字符串标记_TITLE=“TITLE”;
//产品JSONArray
JSONArray产品=null;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u get\u all\u recipes);
//ListView的Hashmap
productsList=新的ArrayList();
//在后台线程中加载产品
新建LoadAllProducts().execute();
//获取列表视图
ListView lv=getListView();
//论单产品的选择
//启动编辑产品屏幕
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
字符串pid=((TextView)view.findViewById(R.id.GetAllscbid)).getText().toString();
//开始新的意图
Intent in=新Intent(getApplicationContext(),EditRecipeActivity.class);
//将pid发送到下一个活动
in.putExtra(标签SCB ID,pid);
//开始新的活动并期望得到一些响应
startActivityForResult(in,100);
}
});
}//结束一次创建方法
//编辑产品活动的响应
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
//如果结果代码为100
如果(结果代码==100){
//如果收到结果代码100
//指用户编辑/删除的产品
//重新加载此屏幕
Intent=getIntent();
完成();
星触觉(意向);
}
}
/**
*通过发出HTTP请求加载所有产品的后台异步任务
* */
类LoadAllProducts扩展了AsyncTask{
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=newprogressdialog(GetAllRecipesActivity.this);
pDialog.setMessage(“正在加载产品。请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
/**
*从url获取所有产品
* */
受保护的字符串doInBackground(字符串…args){
//建筑参数
List params=new ArrayList();
//从URL获取JSON字符串
JSONObject json=jParser.makeHttpRequest(url_all_products,“GET”,params);
//检查日志cat中的JSON响应
Log.d(“所有产品:,json.toString());
试一试{
//检查成功标签
int success=json.getInt(TAG_success);
如果(成功==1){
//发现的产品
//获取一系列产品
products=json.getJSONArray(TAG_products);
//在所有产品中循环
对于(int i=0;ivalue
地图放置(标签SCB ID,ID);
地图放置(标签标题、名称);
//将哈希列表添加到ArrayList
productsList.add(地图);
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/GetAllscbid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="@+id/GetAllTitle"
android:layout_width="269dp"
android:layout_height="34dp" />
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
private static final String TAG_PRODUCTS = "products";