Onclicklistener没有在我的listview上工作

时间:2015-07-25 07:35:08

标签: java android android-listview

这是实现onclicklistener但不起作用的代码

protected void onPostExecute(JSONObject json) {
             pDialog.dismiss();

             try {
                    android = json.getJSONArray(TAG_OS);
                    for(int i = 0; i < android.length(); i++){
                    JSONObject c = android.getJSONObject(i);
                    String name = c.getString(TAG_VER);
                    String number = c.getString(TAG_NAME);
                    String price = c.getString(TAG_PRICE);
                HashMap<String, String> map = new HashMap<String, String>();
                    map.put(TAG_VER, name);
                    map.put(TAG_NAME, number);
                    map.put(TAG_PRICE, price);
                    oslist.add(map);
                    list=(ListView)findViewById(R.id.listView1);
                    ListAdapter adapter = new SimpleAdapter(SearchPart.this, oslist,
                            R.layout.list3,
                            new String[] { TAG_VER ,TAG_NAME,TAG_PRICE}, new int[] {
                                    R.id.pname,R.id.pnumber,R.id.pprice});


                    list.setAdapter(adapter);
                    list.setOnItemClickListener(new OnItemClickListener() {

                        @Override
                        public void onItemClick(AdapterView<?> parent, View view,int position, long id) {


                            // TODO Auto-generated method stub
                            //Toast.makeText(SearchPart.this, "You Clicked at ", Toast.LENGTH_SHORT).show();
                            Toast.makeText(getApplicationContext(),"Hello Javatpoint",Toast.LENGTH_SHORT).show();   

                        }
                    });
                    }
                 } catch (JSONException e) {}


}

1 个答案:

答案 0 :(得分:0)

哦,我找到了答案。问题不是我的java而是xml。在这里结账:OnItemCLickListener not working in listview