简体   繁体   English

在我的android应用程序中显示黑屏-在Eclipse中

[英]Displays a black screen in my android application - in Eclipse

I am a beginner in programming for Android and I have a big problem. 我是Android编程的初学者,但遇到了很大的问题。 Use development environment Eclispe. 使用开发环境Eclispe。 Creating stopwatch application, but always in my application displays only a black screen. 创建秒表应用程序,但始终在我的应用程序中仅显示黑屏。 Since the beginning of the creation of the project over my phone is connected via an Android ADB in shows only a black screen. 由于通过手机创建项目的开始是通过Android ADB连接的,因此仅显示黑屏。 I looked at some threads on this site, but I still do not know what the problem is. 我查看了该站点上的一些线程,但是我仍然不知道问题出在哪里。

My MainActivity.java file: 我的MainActivity.java文件:

package cz.miegl.stopky;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.SystemClock;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends Activity {

    private TextView textTimer;
    private Button startButton;
    private Button pauseButton;
    private long startTime = 0L;
    private Handler myHandler = new Handler();
    long timeInMillies = 0L;
    long timeSwap = 0L;
    long finalTime = 0L;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        textTimer = (TextView) findViewById(R.id.textTimer);

        startButton = (Button) findViewById(R.id.btnStart);
        startButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                myHandler.postDelayed(updateTimerMethod, 0);

            }
        });

        pauseButton = (Button) findViewById(R.id.btnPause);
        pauseButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                timeSwap += timeInMillies;
                myHandler.removeCallbacks(updateTimerMethod);

            }
        });

    }

    private Runnable updateTimerMethod = new Runnable() {

        public void run() {
            timeInMillies = SystemClock.uptimeMillis() - startTime;
            finalTime = timeSwap + timeInMillies;

            int seconds = (int) (finalTime / 1000);
            int minutes = seconds / 60;
            seconds = seconds % 60;
            int milliseconds = (int) (finalTime % 1000);
            textTimer.setText("" + minutes + ":"
                    + String.format("%02d", seconds) + ":"
                    + String.format("%03d", milliseconds));
            myHandler.postDelayed(this, 0);
        }

    };

}

My activity_main.xml file: 我的activity_main.xml文件:

<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"
    android:background="@android:color/white" >
    <Button

    android:id="@+id/btnPause"
    android:layout_width="90dp"
    android:layout_marginLeft="20dp"
    android:layout_height="45dp"
    android:layout_centerVertical="true"
    android:layout_toRightOf="@+id/btnStart"
    android:text="Pauza" />

    <Button
    android:id="@+id/btnStart"
    android:layout_width="90dp"
    android:layout_height="45dp"

    android:layout_alignParentLeft="true"
    android:layout_centerVertical="true"
    android:layout_marginLeft="68dp"
    android:text="Start" />

    <TextView
    android:id="@+id/textTimer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/btnPause"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="37dp"
    android:textSize="40sp"
    android:textColor="#000000"
    android:text="00:00:00" />

</RelativeLayout>

And my AndroidManifest.xml file: 还有我的AndroidManifest.xml文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="cz.miegl.stopky"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="19" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="cz.miegl.stopky.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Please help me. 请帮我。 I do not know what to do. 我不知道该怎么办。 Thank you! 谢谢!

Please HELP ME!!! 请帮我!!! Thanks! 谢谢!

Right now it looks like you're mixing the main activity and the main fragment together. 现在看来,您正在将主要活动和主要片段混合在一起。 I'm still new to fragments, but I'm pretty sure that in your activity's OnCreate, you want to call 我仍然不熟悉片段,但是我很确定在您活动的OnCreate中,您想调用

setContentView(R.id.activity_main)

and then in activity_main.xml, reference the fragment. 然后在activity_main.xml中引用该片段。

Check out the fragment programming guide at http://developer.android.com/guide/topics/fundamentals/fragments.html http://developer.android.com/guide/topics/fundamentals/fragments.html上查看片段编程指南。

You have a framelayout in your activity_main.xml file. 您的activity_main.xml文件中有一个框架布局。 This is a placeholder for another view, and therfore does not show anything. 这是另一个视图的占位符,因此不显示任何内容。 Normally you would use this view when you are using fragments. 通常,在使用片段时会使用此视图。 You are however not using fragments. 但是,您没有使用片段。

Since you are a beginner copy the entire content from fragment_main into the activity_main.xml file. 由于您是初学者,请将整个内容从fragment_main复制到activity_main.xml文件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM