문제

Stopwatch GDK 예제의 지침 및 규칙으로 인해 MenuOption을 열 수 없습니다.

내 앱 컴파일하고 "@@@ test"의 임베디드 로그 문을 출력 할 수 있지만 옵션 메뉴가 나타나지 않습니다.

https://developers.google.com/glass/develop/GDK / UI / 침지 - 메뉴

메뉴의 Android API의 메서드입니다.

openOptionsMenu();
.

스톱워치의 규칙의 코드를 기반으로합니다.

/*
 * 
 * Menu Code
 */
protected void onCreate(Bundle savedInstanceState){ 
    super.onCreate(savedInstanceState);
}

 @Override
public boolean onKeyDown(int keycode, KeyEvent event) {
    if (keycode == KeyEvent.KEYCODE_DPAD_CENTER) {
        openOptionsMenu();
        Log.v("@@@@","TEST");
        return true;
    }
    return false;
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu, menu);
    return true;
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    // Implement if needed
    return false;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection. Menu items typically start another
    // activity, start a service, or broadcast another intent.
    switch (item.getItemId()) {
        case R.id.stop:
            //startActivity(new Intent(this, StopStopWatchActivity.class));
            Log.v("@@@@","HI");
                return true;
        case R.id.read_aloud:
            Log.v("@@@@","READ_ALOUD");
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
    //open the optionsMenu to make sure
@Override
public void openOptionsMenu() {
        super.openOptionsMenu();

}
.

메뉴의 XML

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:id="@+id/read_aloud"
        android:title="@string/read_aloud"
        android:icon="@drawable/ic_launcher"/>
    <item
        android:id="@+id/stop"
        android:title="@string/stop"
        android:icon="@drawable/ic_launcher"/>
</menu>
.

도움이 되었습니까?

해결책

편집 : 내 문제가 무엇인지 발견했습니다.나는 FALSE를 반환하는 준비된 옵션을 논평하였으며, 이는 내 옵션을 종사하지 않을 것입니다.

참조에서는 제대로 수행하는 좋은 예입니다.

@ w9jds 그의 도움을 위해

코드가 내 코드에 무엇이 있는지 찾을 수는 없지만 올바른 메뉴 생성과 하나의 탭이있는 작업 예제 솔루션이 있습니다.

https://github.com/w9jds/glassmenuexample

프로그램의 어떤 앱이 헬로 월드 카드를 렌더링하는 유리 앱을 보여주는 것입니다.탭 탭 카드는 '공유'옵션이있는 옵션 메뉴를 만듭니다.

이 기능은 카드가 타임 라인에서 작동하는 방법과 훨씬 유사합니다.

메뉴 - main.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >

     <item
        android:id="@+id/share_menu_item"
        android:title="@string/share_label"
        android:icon="@drawable/ic_share_50"/>

</menu>
.

주요 활동

package com.example.glassmenuexample;

import com.google.android.glass.app.Card;
import com.google.android.glass.media.Sounds;
import com.google.android.glass.touchpad.Gesture;
import com.google.android.glass.touchpad.GestureDetector;

import android.media.AudioManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;

public class MainActivity extends Activity 
{
    private GestureDetector mGestureDetector;

    private AudioManager maManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);

        //initialize the audio manager
        maManager = (AudioManager) getSystemService(this.AUDIO_SERVICE);
        //create gesture listener
        mGestureDetector = createGestureDetector(this);

        //create a new card for the view
        Card cView = new Card(this);
        //set the text of the card to the hello world string
        cView.setText(R.string.hello_world);
        //set the card as the content view
        setContentView(cView.toView());


    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) 
    {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


    private GestureDetector createGestureDetector(Context context) 
    {
        GestureDetector gdDetector = new GestureDetector(context);
        //Create a base listener for generic gestures
        gdDetector.setBaseListener( new GestureDetector.BaseListener() 
        {
            @Override
            public boolean onGesture(Gesture gesture) 
            {
                if (gesture == Gesture.TAP) 
                {
                    //play the tap sound
                    maManager.playSoundEffect(Sounds.TAP);
                    //open the menu
                    openOptionsMenu();
                    return true;
                } 

                return false;
            }
        });

        return gdDetector;
    }

    @Override
    public boolean onGenericMotionEvent(MotionEvent event) 
    {
        if (mGestureDetector != null) 
            return mGestureDetector.onMotionEvent(event);

        return false;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) 
    {
        // Handle item selection. Menu items typically start another
        // activity, start a service, or broadcast another intent.
        switch (item.getItemId()) 
        {
            case R.id.share_menu_item:
                //do something on menu item click
                return true;
            default:
                return super.onOptionsItemSelected(item);
        }
    }

}
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top