0

最初に、ハッシュマップの配列でインテントを作成しようとします インテントは1つのクラスにすぎず、機能します

        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 に答える