-10

我的代码有点问题

这是我的代码

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.....

这就是我想问的......对于每一个帮助,我将不胜感激

谢谢你 :)

4

1 回答 1

2

+=符号用于附加文本。

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

于 2013-01-01T12:21:18.330 回答