2012-03-20 12 views
0

私は、サーバーからデータを取得し、各3秒後に内容を変更するカスタムリストビューを持っています。リストの各行には、ipaddress、statustext、duration時間、noofvisit、およびボタンのテキストが含まれています。この部分はうまくいきます。androidのlistviewの一番上の行に特定のテキストを持つカスタムリストビューの行を挿入する方法

実際には、ステータステキストがチャットリクエストの場合は、リストビューの最初の行に問題があります。これを行うにはどうすればよいですか?

実際に私はログイン画面の後にタブホストを使用していますtabhostは、訪問者のリストを表示する監視ウィンドウ用のタブ1と、チャットウィンドウ、オペレータリストとコントロールです。

ステータスチャットリクエストを受け取った場合は、その行が上部に表示され、2つのボタンが含まれます。承諾と拒否ボタンをクリックしてチャット用のウィンドウを開き、拒否するチャットを拒否します。

誰でもこの問題の解決に手伝ってもらえますか?

私のコードは、私は誰も私を助けることができますか?上の要求をチャットしている行を設定するために何ができる

public class BaseActivity extends Activity { 

private ListView list =null; 
private NotificationManager mNotificationManager; 

private final int NOTIFICATION_ID = 1010; 
public static Timer timer = new Timer(); 
private String response; 
protected Dialog m_ProgressDialog; 
String[] operatorList,operatorDetail,operatordetail,tempoperatordata; 
String[] noofvisitors,opt; 
private static final String DEB_TAG = "Error Message"; 
public static ArrayList<String> SessionText,IPText,DurationText,StatusText; 
private ArrayList<String> NoOfVisit,ButtonText; 
private int sizeoflist; 
private String IP; 
Context context; 
private CustomAdapter adapter; 
public static String from,sessionid,id,text,iptext,status,temo; 
private int position,noofchat; 
private boolean IsSoundEnable,IsChatOnly; 
private Button logout; 

NotificationManager notificationManager; 



final HashMap<String, String> postParameters = new HashMap<String, String>(); 
private String url; 

private Handler handler; 





public void TimerMethod() 
{ 
    //This method is called directly by the timer 
    //and runs in the same thread as the timer. 

    //We call the method that will work with the UI 
    //through the runOnUiThread method. 
    this.runOnUiThread(Timer_Tick); 

} 

private Runnable Timer_Tick = new Runnable() { 
    public void run() { 

     //This method runs in the same thread as the UI.    
     try{ 

      getVisitorDetailFromServer(); 
     }catch(Exception e){ 
      e.printStackTrace(); 
     } 


     try { 
      Log.i("UPDATE", "Handler called"); 

      list.invalidateViews(); 
      playSound3(); 


     } catch(Exception e) { 
      Log.e("UPDATE ERROR", "error"); 
     } 


    } 


}; 


@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.visitor); 

    list = (ListView) findViewById(R.id.list01); 

    logout = (Button) findViewById(R.id.btnlogout); 

    //list.addView("chat request", 0); 





    //-----------------Making the object of arrayList---------------- 

    SessionText = new ArrayList<String>(); 
    IPText = new ArrayList<String>(); 
    DurationText = new ArrayList<String>(); 
    StatusText = new ArrayList<String>(); 
    NoOfVisit = new ArrayList<String>(); 
    ButtonText = new ArrayList<String>(); 

    Bundle extras = getIntent().getExtras(); 
    if (extras != null) { 
     IsSoundEnable = Controls.IsSoundEnable; 
     IsChatOnly = Controls.IsChatOnly; 
     IsSoundEnable = extras.getBoolean("IsSoundOnly", Controls.IsSoundEnable); 
     IsChatOnly= extras.getBoolean("IsCOnlyhat", Controls.IsChatOnly); 
     extras.getString("From"); 
     position=extras.getInt("Position"); 


    } 



} 



@Override 
protected void onStart() { 

    super.onStart(); 


    //------------Getting the visitor detail------------------------- 

    try{ 
     getVisitorDetailFromServer(); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 

    timer.schedule(new TimerTask() { 
     public void run() { 
      TimerMethod(); 
     } 

    }, 0, 7000); 




    //---------------When user click on logout button----------------------------------- 


    logout.setOnClickListener(new View.OnClickListener() { 

     public void onClick(View v) { 
      // TODO Auto-generated method stub 

      try{ 
       logoutFromServer(); 

      } 
      catch(Exception e){ 
       e.printStackTrace(); 
      } 



     } 


    }); 


} 

private void playSound3() { 
    // TODO Auto-generated method stub 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.newvisitors); 

    mp.start(); 

} 




//----------------------------Getting the detail from server of monitoring window------------------------- 


private void getVisitorDetailFromServer() { 
    // TODO Auto-generated method stub 



    url = "http://"+Main.tempurl+"/"+Main.url1+"/"+Url.IDS_AllOnline; 
    postParameters.put("adminid",Main.loginId.getText().toString()); 
    postParameters.put("sid",Main.siteId.getText().toString()); 
    postParameters.put("nvar","Y"); 
    postParameters.put("conly", "N"); 


    Runnable searchThread = new Runnable(){ 

     public void run() { 
      // TODO Auto-generated method stub 

      try { 

       response = CustomHttpClient.executeHttpPost1(url,postParameters); 

       Log.i(DEB_TAG, "Requesting to server"+response); 
       //CustomHttpClient.getResponseInString(response); 

       //System.out.println("Output of httpResponse:"+response); 

       String result = response; 
       result = response; 

       String delimiter1 = "<ln>"; 
       String delimiter2 = "<blk>"; 

       String[] temp = result.split(delimiter2); 
       operatorDetail = result.split(delimiter1); 
       if(temp.length==7){ 
        String visitorString = temp[0]; 
        String strSound = temp[3]; 
        String strCSRmsgOrChatTrans = temp[4]; 
        String stroperator = temp[5]; 
        String strvisitor = temp[1]; 

        visitorString = visitorString.trim(); 
        if(!(visitorString.equals(""))||(visitorString.equalsIgnoreCase("No Visitors online")||(visitorString.equalsIgnoreCase("No Users Online")))){ 
         operatorDetail = result.split(delimiter1); 
         //sizeoflist =operatorDetail.length; 
        } 
        else{ 

         sizeoflist = 0; 
        } 

       } 

       else{ 

        sizeoflist = operatorDetail.length; 
       } 

       //System.out.println("operatordetail length"+operatorDetail.length); 


       System.out.println("firstresponse================"+operatorDetail[0]); 
       if(operatorDetail[0].equalsIgnoreCase("logout")){ 
        sizeoflist = 0; 
        System.exit(0); 
        finish(); 
       } 

       if(temp[0].equalsIgnoreCase("No Users Online")){ 
        if(temp[1].equalsIgnoreCase("0")){ 
         sizeoflist =0; 
       } 
        else if(temp[1].length()>0){ 
         sizeoflist = 0; 
        } 
        else if(temp[0].equalsIgnoreCase("")){ 
         sizeoflist = 0; 
        } 
        sizeoflist =0; 
       } 
       else{ 
        sizeoflist =operatorDetail.length; 
       } 





       //operatorDetail = result.split(delimiter1); 

       //--------Getting the size of the list--------------------- 

      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if(response!=null){ 



       runOnUiThread(new Runnable() { 

        public void run() { 
         // TODO Auto-generated method stub 
         //playsound3(); 
         noofchat =0; 

         list.setAdapter(new CustomAdapter(BaseActivity.this)); 

         list.getDrawingCache(false); 
         list.invalidateViews(); 
         list.setCacheColorHint(Color.TRANSPARENT); 
         list.requestFocus(0); 
         list.setFastScrollEnabled(true); 
         //list.setSelected(true); 


         list.setOnItemClickListener(new OnItemClickListener() { 
          @Override 
          public void onItemClick(AdapterView<?> parent, View view, int position, 
            long id) { 

           String item = ((TextView)view).getText().toString(); 

           Toast.makeText(getBaseContext(), item, Toast.LENGTH_LONG).show(); 

          } 


         }); 


        } 


       }); 
      } 

      else { 

       //ShowAlert(); 
      } 


     } 
    }; 

    Thread thread = new Thread(null, searchThread, "MagentoBackground"); 
    thread.start(); 




} 


//--------------------When internet connection is failed show alert 

private void ShowAlert() { 
    // TODO Auto-generated method stub 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    final AlertDialog alert = builder.create(); 
    alert.setTitle("Live2Support"); 
    alert.setMessage("Internet Connection failed"); 
    alert.setButton("OK", new DialogInterface.OnClickListener() { 

     public void onClick(DialogInterface dialog, int which) { 
      // TODO Auto-generated method stub 
      //startActivity(new Intent(CreateAccount.this,CreateAccount.class)); 
      alert.dismiss(); 

     } 
    }); 

    alert.show(); 
} 


//------------------------Getting the notification of no.of visitor on the site--------------------------- 

private void triggerNotification() { 
    // TODO Auto-generated method stub 
    CharSequence title = "No Of visitors"; 
    CharSequence message = "New visit"; 
    NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); 
    Notification notification = new Notification(R.drawable.icon, noofvisitors[0], System.currentTimeMillis()); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 


    Intent notificationIntent = new Intent(this, L2STest.class); 
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); 

    notification.setLatestEventInfo(BaseActivity.this, title, noofvisitors[0], pendingIntent); 
    notificationManager.notify(NOTIFICATION_ID, notification); 
    playsound4(); 

} 

public void completed() { 
    //remove the notification from the status bar 
    mNotificationManager.cancel(NOTIFICATION_ID); 
} 


private void playsound4() { 
    // TODO Auto-generated method stub 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.newvisitsound); 

    mp.start(); 

} 



//-----------------Logout from server-------------------- 

private void logoutFromServer() { 
    // TODO Auto-generated method stub 
    final String url ="http://"+Main.tempurl+"/"+Main.url1+"/"+Url.IDS_LOGOUT; 

    final HashMap<String, String> postParameters = new HashMap<String, String>(); 
    try{ 
     postParameters.put("adminid",Main.loginId.getText().toString()); 
     postParameters.put("sid",Main.siteId.getText().toString()); 
    }catch(Exception e){ 
     e.printStackTrace(); 
    } 

    Runnable searchThread = new Runnable(){ 

     public void run() { 
      // TODO Auto-generated method stub 

      try { 
       response = CustomHttpClient.executeHttpPost1(url,postParameters); 

       Log.i(DEB_TAG, "Requesting to server"+response); 

       //CustomHttpClient.getResponseInString(response); 

       System.out.println("Output of httpResponse:"+response); 







      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if(response!=null){ 

       runOnUiThread(new Runnable() { 

        public void run() { 
         // TODO Auto-generated method stub 
         // notificationManager.cancelAll();] 


         System.out.println(response); 
         showAlert1(); 

         //getSharedPreferences(Main.PREFS_NAME,MODE_PRIVATE).edit().clear().commit(); 
         Log.e(DEB_TAG, response); 
         //System.exit(0); 
         Intent intent = new Intent(BaseActivity.this,Main.class); 
         startActivity(intent); 
         //closeHandler(); 

        } 


       }); 
      } 


     } 


    }; 

    Thread thread = new Thread(null, searchThread, "MagentoBackground"); 
    thread.start(); 


} 



//----------------------Logout alert when user click on logout button------------------ 


private void showAlert1() { 
    // TODO Auto-generated method stub 
    int duration = Toast.LENGTH_SHORT; 
    Context context = getApplicationContext(); 
    CharSequence text = "You have Successfully logout."; 
    Toast toast = Toast.makeText(context, text, duration); 
    toast.setGravity(Gravity.TOP|Gravity.LEFT, 200, 200); 
    toast.show(); 
} 



//-------------------Play sound3 when any new user visit---------------- 


private void playsound3() { 
    // TODO Auto-generated method stub 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.newvisitors); 

    mp.start(); 

} 


//------------------The adapter class------------------------------ 


private class CustomAdapter extends BaseAdapter { 
    private LayoutInflater mInflater; 




    public CustomAdapter(Context context) { 

     mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     this.notifyDataSetChanged(); 

     SessionText.clear(); 
     IPText.clear(); 
     DurationText.clear(); 
     StatusText.clear(); 
     NoOfVisit.clear(); 
     ButtonText.clear(); 



    } 


    public int getCount() { 
     return sizeoflist; 
    } 

    public Object getItem(int position) { 
     return position; 
    } 

    public long getItemId(int position) { 
     return position; 
    } 

    /* (non-Javadoc) 
    * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup) 
    */ 
    public View getView(final int position, View convertView, ViewGroup parent) { 
     final ViewHolder holder; 
     if (convertView == null) { 

      convertView = mInflater.inflate(R.layout.row1, null); 
      holder = new ViewHolder(); 
      holder.IP = (TextView) convertView.findViewById(R.id.ip); 
      holder.duration = (TextView) convertView.findViewById(R.id.duration); 
      holder.status =(TextView) convertView.findViewById(R.id.status); 
      holder.noOfVisit = (TextView) convertView.findViewById(R.id.NoOfvisit); 
      holder.invite =(Button)convertView.findViewById(R.id.btnjoin); 
      holder.deny = (Button) convertView.findViewById(R.id.btndeny); 
      //holder.accept = (Button) convertView.findViewById(R.id.btnaccept); 


      holder.deny.setVisibility(View.INVISIBLE); 

      holder.invite.setId(position); 
      holder.invite.setTag(position); 

      convertView.setTag(holder); 
     } else { 
      holder = (ViewHolder) convertView.getTag(); 

     } 


     String result = response; 

     String delimiter = "<fld>"; 
     String delimiter1 = "<ln>"; 



     for(int i=0;i<operatorDetail.length;i++){ 
      if(operatorDetail!=null){ 

       //System.out.println("Operator res=============="+operatorDetail[i]); 


       operatorList = operatorDetail[i].split(delimiter); 

       try{ 

        if(operatorList[0]!=null){ 
         SessionText.add(operatorList[0]); 
         sessionid = operatorList[0]; 
        } 
        else{ 
         onStart(); 
        } 
       }catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(operatorList[1]!=null){ 
         IPText.add(operatorList[1]); 
         iptext = operatorList[1]; 
        } 
        else{ 
         System.out.println("Oplst is null"); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(operatorList[4]!=null){ 
         DurationText.add(operatorList[4]); 
        } 
        else{ 
         System.out.println("Oplst is null"); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(operatorList[3]!=null){ 
         StatusText.add(operatorList[3]); 
         status = operatorList[3]; 
        } 
        else{ 
         System.out.println("Oplst is null"); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(operatorList[2]!=null){ 
         NoOfVisit.add(operatorList[2]); 
        } 
        else{ 
         System.out.println("Oplst is null"); 
        } 
       }catch(Exception e){ 
        e.printStackTrace(); 
       } 
       //ButtonText.add(operatorList[6]); 




       try{ 
        if(IPText!=null){ 

         holder.IP.setText(IPText.get(position)); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(DurationText!=null){ 

         holder.duration.setText(DurationText.get(position)); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 
       try{ 
        if(StatusText!=null){ 

         holder.status.setText(StatusText.get(position)); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 

       try{ 
        if(NoOfVisit!=null){ 
         holder.noOfVisit.setText(NoOfVisit.get(position)); 
        } 
       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 




       //----------------If status is chat request then check for this----------------- 

       try{ 
        if(StatusText.get(position).equalsIgnoreCase("chat request")){ 
         //playsound(); 
         playsound(); 
         holder.deny.setVisibility(View.VISIBLE); 
         holder.invite.setText("Accept"); 
         holder.deny.setText("Deny"); 
         convertView.bringToFront(); 
         convertView.setFocusableInTouchMode(true); 
         convertView.setSelected(true); 
         //convertView.setFocusable(true); 
         convertView.requestFocus(); 
         convertView.clearFocus(); 


         holder.invite.setOnClickListener(new View.OnClickListener() { 

          public void onClick(View v) { 
           // TODO Auto-generated method stub 
           holder.invite.setText("Join"); 
           holder.deny.setVisibility(View.INVISIBLE); 

           try{ 
            chatRequest(IPText.get(position), SessionText.get(position)); 
           } 
           catch(Exception e){ 
            e.printStackTrace(); 
           } 
           Intent i = new Intent(BaseActivity.this,Chat1.class); 
           i.putExtra("ID", id); 
           i.putExtra("Position",position); 
           i.putExtra("From", from); 
           try{ 
            i.putExtra("SessionText",SessionText.get(position)); 
            i.putExtra("IPTEXT",IPText.get(position)); 
            i.putExtra("StatusText",StatusText.get(position)); 
           } 
           catch(Exception e){ 
            e.printStackTrace(); 
           } 
           startActivity(i); 
          } 
         }); 

        } 
        else{ 
         holder.invite.setText("Invite"); 
         holder.deny.setVisibility(View.INVISIBLE); 
         //---------------------When user click on invite Button--------------------- 


         holder.invite.setOnClickListener(new View.OnClickListener() { 

          public void onClick(View v) { 
           // TODO Auto-generated method stub 
           timer.purge(); 

           try{ 
            if(SessionText!=null){ 
             callToServer(SessionText.get(position)); 
            } 

            else{ 

             System.out.println("null"); 

            } 
           } 
           catch(Exception e){ 

            e.printStackTrace(); 


           } 

          } 
         }); 


        } 

       } 
       catch(Exception e){ 
        e.printStackTrace(); 
       } 







       //-----------------------------When user click on deny button------------------------ 

       holder.deny.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View v) { 
         // TODO Auto-generated method stub 
         timer.purge(); 
         try{ 
          if(SessionText.get(position)!=null){ 
           refuseToServer(SessionText.get(position)); 
           holder.deny.setVisibility(View.INVISIBLE); 
          } 
          else{ 
           System.out.println("null"); 
          } 
         }catch(Exception e){ 
          e.printStackTrace(); 
         } 


        } 




       }); 


       //-----------When user click on the listiview row----------------------- 

       convertView.setOnClickListener(new OnClickListener(){ 

        public void onClick(View v) { 
         timer.purge(); 

         if(SessionText!=null&&IPText!=null){ 
          try{ 
           Intent i=new Intent(BaseActivity.this,VisitorDetail.class); 
           i.putExtra("ID", id); 
           i.putExtra("Position",position); 
           i.putExtra("From", from); 
           i.putExtra("SessionText", sessionid); 
           i.putExtra("IPTEXT",iptext); 
           startActivity(i); 

          }catch(Exception e){ 
           e.printStackTrace(); 
          } 

         } 

         else{ 

          timer.schedule(new TimerTask() { 
           public void run() { 
            TimerMethod(); 
           } 

          }, 0, 5000); 
         } 



        }}); 


      } 

     } 

     operatorDetail=null; 
     operatorList=null; 


     operatorDetail = result.split(delimiter1); 



     return convertView; 
    } 


    class ViewHolder { 
     TextView IP; 
     TextView duration; 
     Button deny; 
     TextView status; 
     TextView noOfVisit; 
     Button invite; 
     Button accept; 
    } 
} 


//------------------Play sound when user click on invite button------------------------- 

private void playSound2() { 
    // TODO Auto-generated method stub 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.invite); 

    mp.start(); 

} 


//---------------When any chat request come----------------- 

private void playsound() { 
    // TODO Auto-generated method stub 
    MediaPlayer mp = MediaPlayer.create(this, R.raw.chatinvitation); 

    mp.start(); 

} 



//------------When user click on deny button--------------------- 


private void refuseToServer(String sessionid) { 
    // TODO Auto-generated method stub 
    //final String url = "http://sa.live2support.com/cpn/wz-action.php?"; 
    url = "http://"+Main.tempurl+"/"+Main.url1+"/"+Url.IDS_ACTION; 

    final HashMap<String, String> postParameters = new HashMap<String, String>(); 

    postParameters.put("action","refuse"); 
    postParameters.put("csesid", sessionid); 


    postParameters.put("sid",Main.siteId.getText().toString()); 
    postParameters.put("adminid",Main.loginId.getText().toString()); 


    Runnable searchThread = new Runnable(){ 

     public void run() { 
      // TODO Auto-generated method stub 

      try { 
       response = CustomHttpClient.executeHttpPost1(url,postParameters); 

       Log.i(DEB_TAG, "Requesting to server"+response); 
       //CustomHttpClient.getResponseInString(response); 


       System.out.println("Deny Chat response:"+response); 


       System.out.println("Deny chat Success"+IP); 


      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if(response!=null){ 

       runOnUiThread(new Runnable() { 

        public void run() { 
         // TODO Auto-generated method stub 

         System.out.println("response================="+IP); 

         showAlert(IP); 

        } 



       }); 
      } 


     } 


    }; 

    Thread thread = new Thread(null, searchThread, "MagentoBackground"); 
    thread.start(); 

} 



//---------------------When user click on invite button----------------------- 


private void callToServer(String session) { 
    // TODO Auto-generated method stub 

    url = "http://"+Main.tempurl+"/"+Main.url1+"/"+Url.IDS_ACTION; 

    final HashMap<String, String> postParameters = new HashMap<String, String>(); 

    postParameters.put("action","cinvt"); 
    postParameters.put("csesid", session); 

    postParameters.put("sid",Main.siteId.getText().toString()); 
    postParameters.put("adminid",Main.loginId.getText().toString()); 


    Runnable searchThread = new Runnable(){ 

     public void run() { 
      // TODO Auto-generated method stub 

      try { 
       response = CustomHttpClient.executeHttpPost1(url,postParameters); 

       Log.i(DEB_TAG, "Requesting to server"+response); 
       //CustomHttpClient.getResponseInString(response); 


       System.out.println("Output of httpResponse:"+response); 

       IP = response; 
       System.out.println("the resultant ip ===================="+IP); 


      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if(response!=null){ 

       runOnUiThread(new Runnable() { 

        public void run() { 
         // TODO Auto-generated method stub 
         playSound2(); 

         System.out.println("response================="+IP); 

         showAlert(IP); 

        } 



       }); 
      } 


     } 


    }; 

    Thread thread = new Thread(null, searchThread, "MagentoBackground"); 
    thread.start(); 

} 

//------------------Show invitation alert---------------------- 

private void showAlert(String ip) { 
    // TODO Auto-generated method stub 
    int duration = Toast.LENGTH_SHORT; 
    Context context = getApplicationContext(); 
    CharSequence text = "Invitation sent to "+ip; 
    Toast toast = Toast.makeText(context, text, duration); 
    toast.setGravity(Gravity.TOP|Gravity.LEFT, 50, 50); 
    toast.show(); 
} 


//-----------------When in response we get the chat request-------------------------- 

private void chatRequest(String iptext, String sessionid) { 
    // TODO Auto-generated method stub 

    url = "http://"+Main.tempurl+"/"+Main.url1+"/"+Url.IDS_ONCHATREQUEST; 

    final HashMap<String, String> postParameters = new HashMap<String, String>(); 


    postParameters.put("csesid", sessionid); 
    postParameters.put("ipaddr", iptext); 

    postParameters.put("sid",Main.siteId.getText().toString()); 
    postParameters.put("adminid",Main.loginId.getText().toString()); 
    postParameters.put("join", "Y"); 


    Runnable searchThread = new Runnable(){ 

     public void run() { 
      // TODO Auto-generated method stub 

      try { 
       response = CustomHttpClient.executeHttpPost1(url,postParameters); 

       Log.i(DEB_TAG, "Requesting to server"+response); 
       //CustomHttpClient.getResponseInString(response); 


       System.out.println("Output of httpResponse:"+response); 

       IP = response; 
       System.out.println("the resultant ip ===================="+IP); 


      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
      if(response!=null){ 

       runOnUiThread(new Runnable() { 

        public void run() { 
         // TODO Auto-generated method stub 
         playSound2(); 

         System.out.println("response================="+response); 

         showAlert(IP); 

        } 

       }); 
      } 

     } 


    }; 

    Thread thread = new Thread(null, searchThread, "MagentoBackground"); 
    thread.start(); 

} 



public void onNotifiyDataSetChanged(){ 
    super.notifyAll(); 
} 




@Override 
public boolean onKeyDown(int keyCode, KeyEvent event) { 
    if (keyCode == KeyEvent.KEYCODE_BACK) { 
     Intent i=new Intent(BaseActivity.this,Main.class); 
     i.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);   
     return true;  
    } 
    return super.onKeyDown(keyCode, event); 
} 



} 

に従っていますか?

+0

コードを付けて、それを説明します。問題を正確に示します。 – Snicolas

+0

これらの値を持つ別のクラスがありますか?ipaddress、statustext、duration time、noofvisit、およびボタンのテキスト – 5hssba

+0

これらの値はありません。arraylistを使用しています........... – nikki

答えて

0

visibilityをView.GONEにデフォルト設定してcustomListItemを作成します。チャットリクエストがあったら、その公開設定をView.VISIBLEに変更してリストを更新してください。シンプル。

+0

listitem continue ... – nikki

+0

?質問で実際に必要なことを明確に説明していただけますか? – Rajkiran

+0

はい、ステータスコードにテキストチャットリクエストがある場合は、(StatusText.get(position).equalsIgnoreCase( "chat request"))をチェックしていますので、リストの最初の項目になります。 ........... \ – nikki

0

あなたは、あなたのリストビューの最初の行として、いくつかのビューを追加し、リストアダプタを設定する前にこの

listview.addHeaderView(myHeaderView); 

使用を使用したい場合。

+1

私は自分のリストに追加していれば静的なデータに使うことができますが、リストビューには動的なデータが含まれています........ – nikki

+0

動的な値を示す動的なビューを作成できます。あなたはまた別のビューを膨張させ、ビューにダイナミックデータを設定し、リストヘッダーと同じものを使用することができます –

+0

これを行うための例を教えてください....... – nikki

0

はこのようにしてみてください。..

boolean bool=true; 
    new Thread(new Runnable() { 
      public void run() { 

      while(bool){ 

       int t=StatusText.IndexOf(chat) 
           if(t!=-1) 
           { 
           Collections.swap(StatusText,0,t); 
           Collections.swap(SessionText,0,t); 
           Collections.swap(IPText,0,t); 
          Collections.swap(DurationText,0,t); 
         Collections.swap(NoOfVisit ,0,t); 
         Collections.swap(ButtonText,0,t); 
           } 
          runOnUiThread(new Runnable() { 
        public void run() { 

         adapter.notifyDataSetChanged(); 



        } 
       }); 
+0

これを試しましたか? – 5hssba

+0

はい、私はこれを試してみますが、これは私のケースでは動作していません....... – nikki

+0

意味で..働いていないのですか? nyエラー? – 5hssba

関連する問題