Java 列表视图不是';t填充

Java 列表视图不是';t填充,java,android,Java,Android,有人能帮忙吗。我试图从json响应填充listview。回复是发布的,出于某种原因它没有显示列表?有什么帮助吗 它还在列表视图上停止,只是什么也看不到 extends ListActivity { // Progress Dialog private ProgressDialog pDialog; // Creating JSON Parser object JSONParser jParser = new JSONParser(); ArrayList<HashMap<Str

有人能帮忙吗。我试图从json响应填充listview。回复是发布的,出于某种原因它没有显示列表?有什么帮助吗 它还在列表视图上停止,只是什么也看不到

extends ListActivity {

// Progress Dialog
private ProgressDialog pDialog;

// Creating JSON Parser object
JSONParser jParser = new JSONParser();

ArrayList<HashMap<String, String>> ideasList;

// url to get all products list
private static String url_all_products = "http://theideavault.no-ip.org//android_connect/get_all_products.php";

// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_PRODUCTS = "ideas";
private static final String TAG_IID = "iid";
private static final String TAG_NAME = "idea";

// products JSONArray
JSONArray ideas = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.all_idea);

    // Hashmap for ListView
    ideasList = 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 iid = ((TextView) view.findViewById(R.id.iid)).getText()
                    .toString();

            // Starting new intent
            Intent in = new Intent(getApplicationContext(),
                    EditIdeaActivity.class);
            // sending pid to next activity
            in.putExtra(TAG_IID, iid);

            // starting new activity and expecting some response back
            startActivityForResult(in, 100);
        }
    });

}

// 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(AllIdeasActivity.this);
        pDialog.setMessage("Reteiving Ideas from database. Wooooooo...");
        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 Ideas: ", json.toString());

        try {
            // Checking for SUCCESS TAG
            int success = json.getInt(TAG_SUCCESS);

            if (success == 1) {
                // products found
                // Getting Array of Products
                ideas = json.getJSONArray(TAG_PRODUCTS);

                // looping through All Products
                for (int i = 0; i < ideas.length(); i++) {
                    JSONObject c = ideas.getJSONObject(i);

                    // Storing each json item in variable
                    String iid = c.getString(TAG_IID);
                    String idea = c.getString(TAG_NAME);

                    // creating new HashMap
                    HashMap<String, String> map = new HashMap<String, String>();

                    // adding each child node to HashMap key => value
                    map.put(TAG_IID, iid);
                    map.put(TAG_NAME, idea);

                    // adding HashList to ArrayList
                    ideasList.add(map);
                }
            } else {
                // no products found
                // Launch Add New product Activity
                Intent i = new Intent(getApplicationContext(),
                        NewIdeaActivity.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(
                        AllIdeasActivity.this, ideasList,
                        R.layout.list_idea, new String[] { TAG_IID,
                                TAG_NAME},
                        new int[] { R.id.iid, R.id.idea });
                // updating listview
                setListAdapter(adapter);
            }
        });

    }

}}
扩展ListActivity{
//进度对话框
私人对话;
//创建JSON解析器对象
JSONParser jParser=新的JSONParser();
ArrayList ideasList;
//获取所有产品列表的url
私有静态字符串url\u所有产品=”http://theideavault.no-ip.org//android_connect/get_all_products.php";
//JSON节点名称
私有静态最终字符串标记_SUCCESS=“SUCCESS”;
私有静态最终字符串TAG_PRODUCTS=“ideas”;
私有静态最终字符串标记_IID=“IID”;
私有静态最终字符串标记_NAME=“idea”;
//产品JSONArray
JSONArray=null;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.all_idea);
//ListView的Hashmap
ideasList=newarraylist();
//在后台线程中加载产品
新建LoadAllProducts().execute();
//获取列表视图
ListView lv=getListView();
//论单产品的选择
//启动编辑产品屏幕
lv.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
字符串iid=((TextView)view.findViewById(R.id.iid)).getText()
.toString();
//开始新的意图
Intent in=新的Intent(getApplicationContext(),
编辑活动类);
//将pid发送到下一个活动
in.putExtra(标签IID,IID);
//开始新的活动并期望得到一些响应
startActivityForResult(in,100);
}
});
}
//编辑产品活动的响应
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
//如果结果代码为100
如果(结果代码==100){
//如果收到结果代码100
//指用户编辑/删除的产品
//重新加载此屏幕
Intent=getIntent();
完成();
星触觉(意向);
}
}
/**
*通过发出HTTP请求加载所有产品的后台异步任务
* */
类LoadAllProducts扩展了AsyncTask{
/**
*在启动后台线程显示进度对话框之前
* */
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(AllIdeasActivity.this);
setMessage(“从数据库中接收想法。woooooooo…”);
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){
//发现的产品
//获取一系列产品
ideas=json.getJSONArray(TAG_产品);
//在所有产品中循环
for(int i=0;ivalue
地图放置(标签IID,IID);
地图放置(标签名称、想法);
//将哈希列表添加到ArrayList
添加(地图);
}
}否则{
//没有发现任何产品
//启动添加新产品活动
意图i=新意图(getApplicationContext(),
NewIdeaActivity.class);
//关闭以前的所有活动
i、 添加标志(意图、标志、活动、清除、顶部);
星触觉(i);
}
}捕获(JSONException e){
e、 printStackTrace();
}
返回null;
}
/**
*完成后台任务后,关闭“进度”对话框
* **/
受保护的void onPostExecute(字符串文件\u url){
//获取所有产品后关闭对话框
pDialog.disclose();
//从后台线程更新UI
runOnUiThread(新的Runnable(){
公开募捐{
/**
*将解析的JSON数据更新到ListView中
* */
ListAdapter=新的SimpleAdapter(
AllIdeasActivity.这个,ideasList,
R.layout.list_idea,新字符串[]{TAG_IID,
TAG_NAME},
新的int[]{R.id.iid,R.id.idea});
//更新列表视图
setListAdapter(适配器);
}
});
}
}}

您犯的最大错误是在初始化TAG\u PRODUCTS变量时

错误:

私有静态最终字符串TAG_PRODUCTS=“ideas”

正确值:

私有静态最终字符串TAG_PRODUCTS=“PRODUCTS”

顺便说一句,你是在收集想法还是产品?因为您的响应是针对产品和代码的