我正在尝试创建一个Android服装应用程序,其中只有一个活动,其中包含一个片段.我希望能够根据按钮点击或其他用户操作切换片段.
我可以很好地替换碎片; 但是,当我从屏幕左侧滑动到屏幕右侧时.该应用关闭.我希望这个滑动就像一个后退按钮,而不是退出应用程序.
主要活动
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.wearable.view.WatchViewStub;
public class MainActivity extends FragmentActivity implements FragmentChangeListener {
int fragmentContainerId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
final WatchViewStub stub = (WatchViewStub)findViewById(R.id.watch_view_stub);
// instialize the fragment to the loading page
stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() {
@Override
public void onLayoutInflated(WatchViewStub watchViewStub) {
fragmentContainerId = R.id.fragmentContainer;
if (watchViewStub.findViewById(R.id.fragmentContainer) != null) {
Fragment1 fragment1= new Fragment1 ();
// In case this activity was started with special instructions from …Run Code Online (Sandbox Code Playgroud) 好的,所以我是C++的新手.我确实有一个java背景,但是用c ++我知道我现在必须自己做垃圾收集.
这是我的场景:
int main(){
float * pt;
while(true){
// some code
}
delete pt;
return 0;
Run Code Online (Sandbox Code Playgroud)
假设您处于无休止的循环中,然后您决定通过单击窗口上的关闭按钮来结束程序.关闭程序有什么作用?它是否终止while循环,然后执行delete命令?或者它只是在不完成删除命令的情况下终止程序.