在android中不知道符号“+ =”

时间:2013-01-01 12:18:58

标签: android json

我的代码有点问题

这是我的代码

public class LihatInfo extends Activity {

   TextView error,br1;
   String i,id_kepadatan,returnString;


    /** Called when the activity is first created. */

   @Override


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lihat_info);

        br1=(TextView)findViewById(R.id.berita1);





   }

   public void clickHandler(View view){
    Intent a = null;
    id_kepadatan = "1";
    switch (view.getId()){
    case R.id.lihatInfo:

ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();

        postParameters.add(new BasicNameValuePair("id_kepadatan", id_kepadatan));


/*            String valid = "1";*/      

        String response = null;

        try {

           response = CustomHttpClient.executeHttpPost("http://10.0.2.2/android/lihatInfo.php", postParameters);


           String result = response.toString();  
           //parse json data

              try{
                      returnString = "";


                JSONArray jArray = new JSONArray(result);
                      for(int i=0;i<jArray.length();i++){

                              JSONObject json_data = jArray.getJSONObject(i);
                              Log.i("log_tag","id_kepadatan: "+json_data.getInt("id_kepadatan")+
                                      ", username: "+json_data.getString("username")+
                                      ", nama_jalan: "+json_data.getString("nama_jalan")+
                                      ", status: "+json_data.getString("status")+
                                      ", tanggal: "+json_data.getString("tanggal")+
                                      ", waktu: "+json_data.getString("waktu")+
                                      ", keterangan: "+json_data.getString("keterangan")
                              );

                              //Get an output to the screen
                              returnString += "\n" + json_data.getString("nama_jalan") + " mengalami "+ json_data.getString("status")+ " pada "+ json_data.getString("tanggal")+ " waktu "+ json_data.getString("waktu")+ " karena "+ json_data.getString("keterangan");
                      }
              }


              catch(JSONException e){
                      Log.e("log_tag", "Error parsing data "+e.toString());
              }

              try{


               br1.setText(returnString);


              }


              catch(Exception e){

               Log.e("log_tag","Error in Display!" + e.toString());;          

              }   

         }

               catch (Exception e) {

          Log.e("log_tag","Error in http connection!!" + e.toString());     

         }
        break;

    case R.id.cariPeta2:
        a = new Intent(this,MainActivity2.class);
        startActivity(a);
        break;
   case R.id.kembali2:
        a = new Intent(this, Menu.class);
        startActivity(a);
        break;
}
   }


}

我想问的是

  1. 符号+=在行

    中的含义是什么

    returnString += "\n" + json_data.getString("nama_jalan") + " mengalami "+ json_data.getString("status")+ " pada "+ json_data.getString("tanggal")+ " waktu "+ json_data.getString("waktu")+ " karena "+ json_data.getString("keterangan");

  2. 我可以用String returnString替换String[] returnString吗?因为我想使用ListView,而不是像我上面的代码那样使用TextView .....

  3. 这就是我想问的.....对于每一个帮助,我都会非常感激

    谢谢你:)

1 个答案:

答案 0 :(得分:2)

+ = 符号用于附加文字。

  

ADD - AND赋值运算符,它将右操作数添加到左操作数   并将结果分配给左操作数