0

首先,我尝试使用来自 hashmap 的数组的意图意图只是一个类并且可以工作

        try{

        JSONArray  earthquakes = json.getJSONArray("result");

        for(int i=0;i<earthquakes.length();i++){                        
            HashMap<String, String> map = new HashMap<String, String>();    
            JSONObject e = earthquakes.getJSONObject(i);

            map.put("id",  String.valueOf(i));
            map.put("tempat", "" + e.getString("place"));
            map.put("kode", "" + e.getString("code"));
            map.put("jarak", "Jarak: " +  e.getString("distance"));
            mylist.add(map);            
        }       
    }catch(JSONException e)        {
         Log.e("log_tag", "Error parsing data "+e.toString());
    }

    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, 
                    new String[] { "tempat", "jarak" }, 
                    new int[] { R.id.item_title, R.id.item_subtitle });

    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
            Toast.makeText(KalkulasiJson.this, "ID '" + o.get("id") + "' was clicked.", Toast.LENGTH_SHORT).show(); 

            Intent i = new Intent(KalkulasiJson.this, Details.class);
            startActivity(i);


        }
    });

}

然后我想用数组中的许多类和特定值来制作意图

        try{

        JSONArray  earthquakes = json.getJSONArray("result");

        for(int i=0;i<earthquakes.length();i++){                        
            HashMap<String, String> map = new HashMap<String, String>();    
            JSONObject e = earthquakes.getJSONObject(i);

            map.put("id",  String.valueOf(i));
            map.put("tempat", "" + e.getString("place"));
            map.put("kode", "" + e.getString("code"));
            map.put("jarak", "Jarak: " +  e.getString("distance"));
            mylist.add(map);            
        }       
    }catch(JSONException e)        {
         Log.e("log_tag", "Error parsing data "+e.toString());
    }

    ListAdapter adapter = new SimpleAdapter(this, mylist , R.layout.main, 
                    new String[] { "tempat", "jarak", "kode"  }, 
                    new int[] { R.id.item_title, R.id.item_subtitle, R.id.item_kode });

    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);  
    lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {              
            @SuppressWarnings("unchecked")
            HashMap<String, String> o = (HashMap<String, String>) lv.getItemAtPosition(position);                   
            Toast.makeText(KalkulasiJson.this, "ID '" + o.get("kode") + "' was clicked.", Toast.LENGTH_SHORT).show(); 

            TextView theCode = (TextView) findViewById(R.id.item_kode);
            String Codefix = theCode.getText().toString();

    if(Codefix=="kode001")
    {
        Intent i = new Intent(KalkulasiJson.this, Menu1.class);
        startActivity(i);
    }
    else if(Codefix=="kode005")
    {
        Intent i = new Intent(KalkulasiJson.this, Menu5.class);
        startActivity(i);
    }
    else if(Codefix=="kode003")
    {
        Intent i = new Intent(KalkulasiJson.this, Menu3.class);
        startActivity(i);
    }
    else if(Codefix=="kode089")
    {
        Intent i = new Intent(KalkulasiJson.this, Menu89.class);
        startActivity(i);
    }


        }
    });

}

只有脚本吐司正在工作,意图不受影响

4

1 回答 1

0

尝试:

if(Codefix.equals("kode001"))...
于 2012-08-21T12:48:16.130 回答