开发者

How to refresh Activity

Actually in my app i have a button on an listView..now on click of that button i have done some changes..so when i move to previous activity after than this changes should appear on that activity..but in my case the changes occur but not appears after i exit from the activity where my listView Button is present..so how can i do that so that my changes occur immediately after i exit from my first activity..code i have wrritten:

code for ListView Button Onclick:

public boolean stopC开发者_如何学PythonycleStage(View v)
{
         Button butStop=(Button) findViewById(R.id.butStop);
         TextView setStopTxtViewTitle =(TextView)findViewById(R.id.setStopTxtViewTitle);
         Date currentDate=new Date();

         int iStopStartCount = CycleManager.getSingletonObject().getStopStartCount();
         Date dtStopDate = currentDate;

         CycleManager.getSingletonObject().setStopStartDate(dtStopDate, iStopStartCount);
         Date dtStart = CycleManager.getSingletonObject().getStartDate();

         if (dtStopDate.getTime() == dtStart.getTime())
             CycleManager.getSingletonObject().removeHistoryDate(dtStart);

         butStop.setBackgroundResource(R.drawable.settings_but_disabled);
         setStopTxtViewTitle.setTextColor(Color.parseColor("#808080"));

         return true;
}


In your first activity, you should refresh the view in the onResume function rather than just in the onStart or onCreate.

Refer to the activity documentation to see the lifecycle of an activity

PS: this is just a guess because you have not given enough code to show how you load the data in your 1st acitvity.


Id use onActivityResult() in the waiting activity, and in there I would redraw the elements that should have changed when you clicked your button in the child activity. In any case, onActivityResult() is the correct way to go unless you are not waiting for any data from child activity, then I'd use onResume().

See http://developer.android.com/reference/android/app/Activity.html#StartingActivities for information on what you should use in your particular situation (you didn't exactly give much information :))

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜