2012-05-24 2 views
-1

두 가지 작업을 만들었습니다. 첫 번째 작업에는 구인 정보가 포함되어 있으며 다음 작업 제안은이 작업에 대한 것입니다. 작업 신청 후, 경고 대화 상자가 나타나 작업의 성공 여부를 확인합니다. 그러나이 경고 대화 상자는 값이없는 작업 세부 정보의 관점에서 나타납니다! 어떻게 관리 할 수 ​​있습니까 ??내 alertdialog에 문제가 있습니다

private static final String MY_PREFERENCES = "mespreferences"; 
TextView txt; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.detail_offre); 
    ToggleButton precedent = (ToggleButton)findViewById(R.id.btn_preced); 
    precedent.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      Intent preced = new Intent(DetailsOffre.this, Offres.class); 
      startActivity(preced); 
     }     
    }); 
     Button postuler = (Button)findViewById(R.id.postuler); 
     postuler.setOnClickListener(new View.OnClickListener() { 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       TextView id_offre = (TextView) findViewById(R.id.tv_ID_Off1); 

       SharedPreferences settings = getSharedPreferences(MY_PREFERENCES, 0); 
       SharedPreferences.Editor editor = settings.edit(); 
       editor.putString("idoffre", id_offre.getText().toString()); 
       editor.commit(); 
       Intent intent_postul = new Intent(DetailsOffre.this, Candidature.class); 
       startActivity(intent_postul); 
      }     
     }); 
     Button enregistrer = (Button)findViewById(R.id.enregistrer); 
     enregistrer.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View v) { 
       // TODO Auto-generated method stub 
       TextView id_offre = (TextView) findViewById(R.id.tv_ID_Off1); 
       String idOf = id_offre.getText().toString(); 
       Intent intent_enregist = new Intent(DetailsOffre.this, EnregistrerOffre.class); 
       intent_enregist.putExtra("idoffre",idOf); 
       startActivity(intent_enregist); 
      }  
}); 

LinearLayout rootLayout = new LinearLayout(getApplicationContext()); 
txt = new TextView(getApplicationContext()); 
rootLayout.addView(txt); 
txt.setText("Connexion..."); 
txt.setText(getServerData(URL2)); 
} 
public static final String URL2 = "http://10.0.2.2/mesRequetes/detail_offr.php";  
private String getServerData(String returnString) { 

    InputStream is = null; 
    String result = null; 
    Intent intent3 = getIntent(); 
    String id = intent3.getExtras().getString("idoffre"); 

    ArrayList<NameValuePair> postID = new ArrayList<NameValuePair>(); 
    postID.add(new BasicNameValuePair("idoffre", id)); 

    // Envoie de la commande http 
    try{ 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost(URL2); 
     httppost.setEntity(new UrlEncodedFormEntity(postID)); 
     HttpResponse response = httpclient.execute(httppost); 
     HttpEntity entity = response.getEntity(); 
     is = entity.getContent(); 
    }catch(Exception e){ 
     Log.e("log_tag", "Error in http connection " + e.toString()); 
    } 

    try{ 
     BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); 
     StringBuilder sb = new StringBuilder(); 
     String line = null; 
     while ((line = reader.readLine()) != null) { 
      sb.append(line + "\n"); 
     } 
     is.close(); 
     result=sb.toString(); 
    }catch(Exception e){ 
     Log.e("log_tag", "Error converting result " + e.toString()); 
    } 

    try{ 

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

     TextView numoffre = (TextView) findViewById(R.id.tv_ID_Off1); 
     numoffre.setText(detail.getString("idoffre")); 

     TextView nom_societe = (TextView) findViewById(R.id.tv_societe1); 
     nom_societe.setText(detail.getString("first_name")); 

     TextView poste = (TextView) findViewById(R.id.TV_post1); 
     poste.setText(detail.getString("poste")); 

     TextView ville = (TextView) findViewById(R.id.tv_vill); 
     ville.setText(detail.getString("ville")); 

     TextView details = (TextView) findViewById(R.id.tv_detail); 
     details.setText(detail.getString("details")); 

     TextView d_crea = (TextView) findViewById(R.id.tv_datecrea); 
     d_crea.setText(format_d(detail.getString("created_at"))); 

     TextView idste = (TextView) findViewById(R.id.TV_idsociete1); 
     idste.setText(detail.getString("idsoc")); 

     SharedPreferences settings = getSharedPreferences(MY_PREFERENCES, 0); 
     SharedPreferences.Editor editor = settings.edit(); 
     editor.putString("idsoc", idste.getText().toString()); 
     editor.commit(); 


     Log.i("log_tag","Numero de l'offre:"+detail.getInt("idoffre")+ 
       "poste proposé:"+detail.getString("poste")+ 
       "ville:"+detail.getString("ville")+ 
       "details:"+detail.getString("details")+ 
       "date de creation:"+detail.getString("created_at")+ 
       "identifiant de la société:"+detail.getString("idsoc")+ 
       "nom de la société:"+detail.getString("first_name") 
       ); 
      // Résultats de la requête 
      returnString += "" + jArray.getJSONObject(i); 


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

    return returnString; 

} 

public static StringBuilder format_d(final String s) { 
    String aaaa = s.substring(0, 4); 
    String mm = s.substring(5, 7); 
    String dd = s.substring(8, 10); 
    String heure = s.substring (11); 


return new StringBuilder(dd) 
     .append("/") 
     .append(mm) 
     .append("/") 
     .append(aaaa) 
     .append(" à ") 
     .append(heure);   
} 

activity2에 :

private static final String MY_PREFERENCES = "mespreferences"; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.detail_offre);  
    SharedPreferences sharedPreferences = getSharedPreferences(MY_PREFERENCES, 0); 
    String userId = sharedPreferences.getString("id", ""); 
    String idoffr = sharedPreferences.getString("idoffre", ""); 

    Intent intent_postul = getIntent(); 
    ArrayList<NameValuePair> postCandidature= new ArrayList<NameValuePair>(); 
    postCandidature.add(new BasicNameValuePair("idoffre", idoffr)); 
    postCandidature.add(new BasicNameValuePair("id", userId)); 
    this.sendData(postCandidature); 

} 
private void sendData(ArrayList<NameValuePair> postCandidature) { 
     // TODO Auto-generated method stub 
    try{ 
     HttpClient httpclient = new DefaultHttpClient(); 
     HttpPost httppost = new HttpPost("http://10.0.2.2/mesRequetes/candidature.php"); 
     httppost.setEntity(new UrlEncodedFormEntity(postCandidature)); 

    HttpResponse response = httpclient.execute(httppost); 
    Log.i("postData", response.getStatusLine().toString()); 

    AlertDialog.Builder cand = new AlertDialog.Builder(Candidature.this); 
    cand.setIcon(R.drawable.succes); 
    cand.setTitle("Succès"); 
    cand.setMessage("Votre candidature a bien été transmise"); 
    cand.setPositiveButton("OK", new DialogInterface.OnClickListener(){ 

     public void onClick(DialogInterface dialog, int which) { 
      // TODO Auto-generated method stub 
      Intent offr = new Intent (Candidature.this, Offres.class); 
      startActivity(offr);  
     }}); 
    cand.show(); 

}catch(Exception e){ 
    Log.e("log_tag", "Error in http connection " + e.toString()); 
} 

    } 

답변

0

가 경고 대화 상자에 대해 다음 사용 이 활동 1입니다. 요구 사항을 이해하는 데 필요한 세부 정보를 제공하십시오.

public void Alert(String text, String title) 
    { 
     AlertDialog dialog=new AlertDialog.Builder(context).create(); 
     dialog.setTitle(title); 
     dialog.setMessage(text); 
     if(!title.equals("") && !text.equals("")) 
     { 
      dialog.setButton("OK", 
        new DialogInterface.OnClickListener() 
        { 
         public void onClick(DialogInterface dialog, int whichButton) 
         { 
          // 
         } 
        }); 
      dialog.setButton2("Cancel", 
        new DialogInterface.OnClickListener() 
        { 
         public void onClick(DialogInterface dialog, int whichButton) 
         { 
          // 
         } 
        }); 
     } 

     dialog.show(); 

    } 
+0

내 게시물을 세부 정보로 업데이트했습니다. – androidmee

관련 문제