2012-06-26 56 views
-2
protected void onListItemClick(ListView list, View view, int position, long id) 
    { 
    super.onListItemClick(list, view, position, id); 
    fname=r.get(position); 
    fid=s1.get(position); 

    if(tid!=null) 
    { 
    try{ 
      //http post 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpPost httppost = new HttpPost("http://192.168.0.5/staging/android/add_playlist_songs.php?uid="+uid+"&tid="+tid+"&fid="+fid+"&action=add"); 
      System.out.println("addsongurl==="+ur); 
      System.out.println(httppost); 
      httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); 
      HttpResponse response = httpclient.execute(httppost); 
      HttpEntity entity = response.getEntity(); 
      is = entity.getContent(); 
     } 
    catch(Exception e){ 
      Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show(); 
     } 
      //Convert response to string 
      try 
      { 
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8")); 
      sb = new StringBuilder(); 
      String line = null; 
      while ((line = reader.readLine()) != null) 
      { 
      sb.append(line + "\n"); 
      } 
      is.close(); 
      result = sb.toString(); 
      // Toast.makeText(getBaseContext(),"Song successfully added.",Toast.LENGTH_LONG).show(); 
      } 
      catch(Exception e) 
      { 
      Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show(); 
      }   
      Toast.makeText(this, "Song Added",Toast.LENGTH_SHORT).show(); 

當我點擊列表值意味着網址被擊中,並在當時我想退出此活動,並回到何?如何退出當前活動繼續

+0

嗨我需要一個更多的幫助,當我點擊確定按鈕alertdialogbox我想以前的活動如何? –

回答

0

試試這個way..As我的建議,儘量做到在doInBackground(使用的AsyncTask所有的web服務代碼)和onPostExecute做餘下的過程()如下,

//在onItemclick()

 new GetTask().execute(); 

// GetTask類

  public class GetTask extends AsyncTask<Object, Void, String> { 

      ProgressDialog progdialog; 
       @Override 
    protected void onPreExecute() { 
     super.onPreExecute(); 

     progdialog = ProgressDialog.show(context, null, 
       "loading.."); 

    } 

      @Override 
    protected String doInBackground(Object... params) { 
     //webservice 

     return null; 
    } 

    @Override 
    protected void onPostExecute(String result) { 
     progdialog.dismiss(); 

       // finish the activity.. 
       // if you start this activity without finishing then call as 
        finish(); 
       // if not 
        Intent in=new Intent(currentclass.this,nextactivity.class); 
        startActivity(in); 
        finish(); 


     super.onPostExecute(result); 
    } 


      } 

alertdialog:

   new AlertDialog.Builder(AccountListActivity.this) 
    .setTitle("Title") 
    .setMessage(message)) 
    .setPositiveButton(ok), new DialogInterface.OnClickListener() { 
    @Override 
    public void onClick(DialogInterface dialog,int which) { 
    Intent in = new Intent(currentClass.this,nextactivity.class); 
     startActivity(in); 
    } 
    }).show(); 

它可以幫助你...

+0

我點擊列表視圖,那個時間活動將會關閉,並且可能會發生什麼? –

+0

k我得到它感謝deepa .. –

+0

嗨我需要一個更多的幫助,當我點擊確定按鈕alertdialogbox我想以前的活動如何? –