按钮显示安卓日食



我添加了一个切换按钮,但它没有显示,我不知道为什么。 我已经完成了Android教程,并回顾了代码以及许多其他来源。 目标是在按钮打开时使程序暂停。 目前,该按钮甚至不会出现在用户界面上。 有什么建议吗?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" />
    <ToggleButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:onClick="pauseCounter" />
</RelativeLayout>

package com.evorlor.counter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Intent counter = new Intent(MainActivity.this, Counter.class);
        startActivity(counter);
    }
    public void pauseCounter(View view) {
        Intent pause = new Intent(this, Pause.class);
        startActivity(pause);
    }
    // @Override
    // public boolean onCreateOptionsMenu(Menu menu) {
    // // Inflate the menu; this adds items to the action bar if it is present.
    // getMenuInflater().inflate(R.menu.activity_main, menu);
    // return true;
    // }
}

package com.evorlor.counter;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Pause extends Activity{
    public void onCreate(Bundle instPause) {
        super.onCreate(instPause);
        TextView tv = new TextView(this);
        tv.setTextSize(250);
        tv.setText("PAUSE");
        setContentView(tv);
    }
}

这是我的计数器类。它很混乱。不好意思。这与我迄今为止所达到的一样接近。 帮助将不胜感激! 我花了很多时间在这个可怜的按钮上! 谢谢!

package com.evorlor.counter;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MotionEvent;
import android.widget.TextView;
import android.widget.ToggleButton;
public class Counter extends Activity {
    private int count = 0;
    private int hiCount = 0;
    private boolean capCount = false;
    public void onCreate(Bundle instCounter) {
        super.onCreate(instCounter);
        TextView tv = new TextView(this);
        tv.setTextSize(250);
        if (count < 10000 && capCount == false) {
            tv.setText(Integer.toString(count));
        } else {
            capCount = true;
            if (count >= 10000) {
                hiCount += 10;
                count -= 10000;
            }
            if (hiCount < 100) {
                tv.setText(hiCount + "k+" + count);
            } else {
                tv.setText("Overn100k");
            }
        }
        tv.setGravity(Gravity.CENTER);
        setContentView(tv);
        ToggleButton butPause = new ToggleButton(this);
        if (butPause == null) {
            Intent pause = new Intent(this, Pause.class);
            startActivity(pause);
        }
    }
    // public void pauseCounter(View view) {
    // Intent pause = new Intent(this, Pause.class);
    // startActivity(pause);
    // }
}
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Intent counter = new Intent(MainActivity.this, Counter.class);
    startActivity(counter);
}

您马上开始一项新活动。 这不是一个好主意。
您将看到计数器活动中的内容,而不是主要活动中的内容,这是您看不到切换按钮的原因。注释掉 startActivity() 只是为了检查。

最新更新