0

私が経験しているアンドロイドプログラミングの本の例を使用しています。この演習のポイントは、「about」ボタンをクリックすると、新しいアクティビティが開始され、テキストが表示されることです。IDE のグラフィカル レイアウトにテキストが表示されていても、何らかの理由でテキストが表示されません。携帯電話をエミュレータとして使用しており、Android 4.0.3 を実行しています。エクリプスを使用しています。これが私のコードです:

主な活動:

package org.example.sodoku;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

public class Sudoku extends Activity implements OnClickListener   {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View continueButton= findViewById(R.id.continue_button);
        continueButton.setOnClickListener(this);
        View newButton= findViewById(R.id.new_button);
        newButton.setOnClickListener(this);
        View aboutButton= findViewById(R.id.about_button);
        aboutButton.setOnClickListener(this);
        View exitButton= findViewById(R.id.exit_button);
        exitButton.setOnClickListener(this);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()){
        case R.id.about_button:
            Intent i = new Intent(this, About.class);
            startActivity(i);
            break;
        }

    }
}

メイン xml:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
   xmlns:android="http://schemas.android.com/apk/res/android"
   android:orientation="vertical"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:background="@color/background"
   android:gravity="center"
   android:padding="35dip">
   <TextView
      android:text="@string/main_title"
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_gravity="center"
      android:layout_marginBottom="20dip"
      android:textSize="24.5sp" />
   <TableLayout
      android:layout_height="wrap_content"
      android:layout_width="wrap_content"
      android:layout_gravity="center"
      android:stretchColumns="*">
      <TableRow>
         <Button
            android:id="@+id/continue_button"
            android:text="@string/continue_label" />
         <Button
            android:id="@+id/new_button"
            android:text="@string/new_game_label" />
      </TableRow>
      <TableRow>
         <Button
            android:id="@+id/about_button"
            android:text="@string/about_label" />
         <Button
            android:id="@+id/exit_button"
            android:text="@string/exit_label" />
      </TableRow>
   </TableLayout>
</LinearLayout>

クラスについて:

package org.example.sodoku;

import android.app.Activity;
import android.os.Bundle;


public class About extends Activity {
    protected void OnCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.about);





    }

}

XML について:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dip">


    <TextView
        android:id="@+id/about_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/about_text" >
</TextView>


    </ScrollView>

[編集] 文字列 xml とマニフェストを忘れました:

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="hello">Hello World, Sudoku!</string>
    <string name="app_name">Sudoku</string>
    <string name="main_title">Android Sodoku</string>
    <string name="continue_label">Continue</string>
    <string name="new_game_label">New Game</string>
    <string name="about_label">About</string>
    <color name="background">#3500ffff</color>
    <string name="exit_label">Exit</string>
    <string name="about_title">About Android Sudoku</string>
    <string name="about_text">fuck your ethnicity</string>
</resources>

マニフェスト:

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

    <uses-sdk android:minSdkVersion="10" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".Sudoku"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity 
            android:name=".About"
            android:label="@string/about_title">
        </activity>
    </application>

</manifest>

どんな助けでも大歓迎です、ありがとう。

4

2 に答える 2

6

onCreate()About アクティビティ (compare OnCreate()and ) のメソッドのスペルが間違っているonCreate()ため、実際には基本クラスのメソッドをオーバーライドしていません。onCreate を次のものに置き換えます。

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
}
于 2012-07-26T23:16:11.300 に答える
1

それはあなたを助けるかもしれません。これをabout.xmlとして使用します。

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scroller"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:fillViewport="true" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center_horizontal"
        android:orientation="vertical" >

   <TextView
        android:id="@+id/about_content"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/about_text" >
   </TextView>

   </LinearLayout>

</ScrollView>
于 2012-07-26T22:45:10.863 に答える