English 中文(简体)
我对警报有意见
原标题:I have an issue with my alertdialog

I created two activities: the first one contains details of a job offer, and the next one is to postulate to this job. after applying for the job, an alertdialog appears to confirm the success of the operation. However, this alertdialog appears in the view of the job details without values ! How can I manage this?? This is activity 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 + "
");
        }
        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());
}

    } 
问题回答

提醒对话框使用以下方法。 请提供更多细节以了解您的要求 。

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

    }




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签