2016-11-14 5 views
1

Ich kann den Timer in Listview ausgewählten Element nicht ausführen.Timer läuft immer nur auf ListView letzten Element.Wenn ich auf den zweiten Eintrag in der Listenansicht klicken, muss ich den Timer in Textansicht des zweiten Elements nur ausführen.Aber ich bin immer den Timer zum letzten Gegenstand zu bekommen. Aber ich bekomme Position richtig. Problem ist im Zeitmesserfaden nur. können Sie bitte erklären, wie man den Zeitgeber auf besonders angeklicktem Einzelteil laufen lässt? Hier ist mein CodeWie führe ich den Timer in Listview?

@Override 
    public View getView(final int position, View convertView, ViewGroup parent) { 
    if (inflater == null) 
      inflater = (LayoutInflater) activity 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

     if (convertView == null) 
      convertView = inflater.inflate(R.layout.activity_schedule, null); 
     punchin = (Button) convertView.findViewById(R.id.punchin); 



     resultp = data.get(position); 
     title = (TextView) convertView.findViewById(R.id.title1); 
     TextView location = (TextView) convertView.findViewById(R.id.location); 
     TextView sheduledate = (TextView) convertView.findViewById(R.id.sheduledate); 
     TextView starttime = (TextView) convertView.findViewById(R.id.startendtime); 


     totalworked = (TextView) convertView.findViewById(R.id.totaltimeworked); 
if(buttonclicked.equals("1")){ 


      startTime = SystemClock.uptimeMillis(); 
       // customHandler.postDelayed(updateTimerThread, 0); 
      customHandler.postDelayed(updateTimerThread,0); 




     }else{ 

      totalworked.setText(resultp.get(MyScheduleFragment.TAG_PUNCDURATION)); 


     } 

} 

und mein runnable Timer-Code ist:

public Runnable updateTimerThread = new Runnable() { 
      //Thread mUpdate = new Thread() { 



      public void run() { 



       timeInMilliseconds = SystemClock.uptimeMillis() - startTime; 




       updatedTime = timeSwapBuff + timeInMilliseconds; 

       int secs = (int) (updatedTime/1000); 
       int mins = secs/60; 
       int hrs = mins/60; 
       secs = secs % 60; 
       // int milliseconds = (int) (updatedTime % 1000); 



    totalworked.setText("" + String.format("%02d", hrs) + ":" 
      + String.format("%02d", mins) 
      + ":" 
      + String.format("%02d", secs)); 
} 
+1

Can u Ihre komplette Adapter Code posten? – Raghavendra

+2

Es sieht aus wie Sie "totalworked" als globale Variable gemacht, so denke ich, es durchschleift alle Elemente und schließlich den letzten Wert – Raghavendra

+0

Sie kann nicht den vollständigen Code verstehen.Meine Junior tat das.Wenn Sie wollen, werde ich senden.Aber ich will Lösung . –

Antwort

2
Hope this might help   

@Override 
      public View getView(final int position, View convertView, ViewGroup parent) { 
      if (inflater == null) 
        inflater = (LayoutInflater) activity 
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

       if (convertView == null) 
        convertView = inflater.inflate(R.layout.activity_schedule, null); 
       punchin = (Button) convertView.findViewById(R.id.punchin); 

       resultp = data.get(position); 
       title = (TextView) convertView.findViewById(R.id.title1); 
       TextView location = (TextView) convertView.findViewById(R.id.location); 
       TextView sheduledate = (TextView) convertView.findViewById(R.id.sheduledate); 
       TextView starttime = (TextView) convertView.findViewById(R.id.startendtime); 
       totalworked = (TextView) convertView.findViewById(R.id.totaltimeworked); 
    // Add Click Listener to the TextView 
    totalworked.setOnClickListener(new View.OnClickListener() { 
       @Override 
       public void onClick(View v) { 
       // write your Stuff when he cicks 

        startTime = SystemClock.uptimeMillis(); 
        // customHandler.postDelayed(updateTimerThread, 0); 
        customHandler.postDelayed(updateTimerThread, 0); 
       } 
      }); 
     // code if he dont click on particular Item 
Verwandte Themen