gpt4 book ai didi

android - 如何在 Listview 中运行计时器?

转载 作者:行者123 更新时间:2023-11-29 19:28:59 24 4
gpt4 key购买 nike

我无法在 Listview 所选项目中运行计时器。计时器始终仅在 Listview 的最后一个项目上运行。假设如果我单击 ListView 上的第二个项目,我必须仅在第二个项目的 textview 中运行计时器。但我是总是在最后一个项目上得到计时器。但我得到了正确的位置。问题只在计时器线程中。你能告诉我如何在特定的点击项目上运行计时器吗?这是我的代码

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


}

}

and my runnable timer code is:

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

最佳答案

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

关于android - 如何在 Listview 中运行计时器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40588763/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com