-1

我创建了两个活动:第一个包含工作机会的详细信息,下一个是对这份工作的假设。申请工作后,会出现一个警告对话框以确认操作成功。但是,此警报对话框出现在没有值的作业详细信息视图中!我该如何管理这个?这是活动1:

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);           
}

活动2:

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());
}

    } 
4

1 回答 1

0

使用以下警报对话框。提供更多详细信息以了解您的要求。

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();

    }
于 2012-05-24T16:50:18.157 回答