开发者

ContextMenu shows item I have not specified in context_menu.xml

开发者 https://www.devze.com 2023-02-12 14:04 出处:网络
I\'m an Android noob. I\'m working with MyEclipse, ADT, SDK, Android 2.2, API 8. My Activity looks like this -

I'm an Android noob. I'm working with MyEclipse, ADT, SDK, Android 2.2, API 8.

My Activity looks like this -

package com.vvittal.relativelayout;

import android.app.Activity;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.vie开发者_StackOverfloww.ContextMenu.ContextMenuInfo;
import android.widget.AdapterView.AdapterContextMenuInfo;

public class Login extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    registerForContextMenu(findViewById(R.id.uEntry));
    registerForContextMenu(findViewById(R.id.pwdEntry));
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.login_menu, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item){
    switch (item.getItemId()){
    case R.id.agency_item: System.out.println("----------------"); 
    return true;
    case R.id.prod_cat_item: System.out.println("++++++++++++++++"); 
    return true;
    default: return super.onOptionsItemSelected(item);
    }
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo){
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.context_menu, menu);
    //menu.f
    //menu.setHeaderTitle("Your Options");
}

@Override
public boolean onContextItemSelected(MenuItem item){
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    switch (item.getItemId()) {
    case R.id.option1: ;
    return true;
    case R.id.option2:
        return true;
    default:
        int i = item.getItemId();
        return super.onContextItemSelected(item);
    }
}
}

And my AndroidManifest.xml look like this -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.vvittal.relativelayout"
  android:versionCode="1"
  android:versionName="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".Login"
              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>

The context_menu.xml is as below -

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/option1"
      android:title="@string/yes" />
<item android:id="@+id/option2"
      android:title="@string/no" />
</menu>

The menu on my emulator has an item called "Input Method", in addition to "Yes" and "No" that I have specified in XML.

I'd like to know where this additional item "Input Method" is coming from when I have not specified any in the xml? Also how to I remove it programmatically?


I'd like to know where this additional item "Input Method" is coming from when I have not specified any in the xml?

The operating system will add context menu choices as appropriate for the widget. In the case of EditText widgets, this will include things like cut, copy, paste, select all, and choosing an input method.

Also how to I remove it programmatically?

Please don't. First, they are there to help the user. Second, they are standard for the platform, and users may get irritated if they are not available.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号