我想改變的TextView後每1個minute.The問題是,它正在改變只是一日一次,在其他cases.This其餘同樣是在那裏我使用的是被稱爲每1可運行分鐘:的TextView得到更新一次
public void ReduceTimeIteration()
{
try
{
final Handler m_handler = new Handler();
runOnUiThread(new Runnable() {
@Override
public void run() {
DiscussArrayAdapter.MyMethod(SplashActivity.this,(long)60000);
m_handler.postDelayed(this, 60000);
}
});
}
catch(Exception e)
{
Log.e("Exception: ",e+" in ReduceTimeIteration() of SplashActivity.java");
}
}
這就是我要更新類textview
TimeLeft
:
public class DiscussArrayAdapter extends ArrayAdapter<OneComment> {
private TextView countryName;
private List<OneComment> countries = new ArrayList<OneComment>();
private LinearLayout wrapper;
public View row;
static OneComment coment;
static TextView TimeLeft;
@Override
public void add(OneComment object)
{
try
{
countries.add(object);
super.add(object);
}
catch(Exception e)
{
Log.e("Exception: ",e+" Exception occured in add() of DiscussArrayAdapter.java");
}
}
public DiscussArrayAdapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public int getCount()
{
try
{
return this.countries.size();
}
catch(Exception e)
{
Log.e("Exception: ",e+" Exception occured in getCount() of DiscussArrayAdapter.java");
}
return this.countries.size();
}
public OneComment getItem(int index)
{
try
{
return this.countries.get(index);
}
catch(Exception e)
{
Log.e("Exception: ",e+" Exception occured in getItem() of DiscussArrayAdapter.java");
}
return null;
}
public View getView(int position, View convertView, ViewGroup parent)
{
try
{
row = convertView;
if (row == null) {
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.listitem_discuss, parent, false);
}
wrapper = (LinearLayout) row.findViewById(R.id.wrapper);
coment = getItem(position);
countryName = (TextView) row.findViewById(R.id.comment);
countryName.setText(coment.comment);
TimeLeft = (TextView) row.findViewById(R.id.timeleft);
int hours,minutes,seconds;
if(coment.timeLeft > 0) // When the time is greater than 0
{
if(TimeLeft == null)
{
((ViewGroup) row).addView(TimeLeft);
}
long t = coment.timeLeft - SecureMessagesActivity.TimeChecker();
seconds = (int) (t/1000) % 60 ;
minutes = (int) (t/(1000*60)) % 60;
hours = minutes/60;
TimeLeft.setText("hello");
}
else
{
if(TimeLeft != null)
{
((ViewGroup)TimeLeft.getParent()).removeView(TimeLeft);
}
}
return row;
}
catch(Exception e)
{
Log.e("Exception: ",e+" Exception occured in View getView(int position, View convertView, ViewGroup parent) of DiscussArrayAdapter.java");
}
return row;
}
public static void MyMethod(Activity activity,long time)
{
try
{
if(TimeLeft.getText().equals("hello"))
{
TimeLeft.setText("hi");
}
else if(TimeLeft.getText().equals("hi"))
{
TimeLeft.setText("hello");
}
Toast.makeText(activity, "Value of TextView is "+TimeLeft.getText() , Toast.LENGTH_SHORT).show();
}
catch(Exception e)
{
Log.e("Exception: ", e+" Occured in MyMethod() of DiscussArrayAdapter.java");
}
}
}
我不知道是什麼問題,因爲其中的TextView的timeleft正在改變它的價值只有一次而在其餘的情況下,它r保持一致。請幫助我。提前致謝。
我覺得線程調用一次時間。 – ckpatel
沒有先生,它每60秒調用一次。請看行m_handler.postDelayed(this,60000); – user1726619
嘗試使用'TimeLeft.getText()。toString()。equals(「hello」)' – Pallavi