2

我已经为我的程序准备了一个输入屏幕,并在其中放置了一个edittext和ImageViews。现在的问题是我能够通过虚拟键盘在edittext中键入文本,但问题是在我完成了我的文本之后我无法从编辑文本中出来,光标只停留在编辑文本框中。我在下面有一个 imageView 可以单击以继续使用该表单,但在那个时候它是不可点击的..请帮助!!!

我的代码是

我的 xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
         android:id="@+id/begin_"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="170dp"
         android:layout_marginTop="220dp"
         android:src="@drawable/begin" />

    <ImageView
        android:id="@+id/enter"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="150dp"
        android:layout_marginTop="30dp"
        android:src="@drawable/enter_name" />

     <ImageView
        android:id="@+id/roof"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/roof" />

     <EditText
         android:id="@+id/editText2"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginLeft="180dp"
         android:layout_marginTop="180dp"
         android:ems="8"
         android:inputType="textMultiLine" 
         android:imeOptions="actionDone"/>
</FrameLayout>

我的主要java类

package game.pack;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;

public class Begin extends Activity implements View.OnClickListener  {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

            setContentView(R.layout.entry);

        ImageView begin = (ImageView) findViewById(R.id.begin_);
        begin.setOnClickListener(this);
    }

    public void onClick(View v) {
        switch(v.getId()) {
        case R.id.begin_:
            setContentView(new SushiMain(this));
            break;
        default:
            break;
        }
    }
}

我的 android 清单是

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >

        <activity
            android:name=".FrontScreen"
            android:screenOrientation="landscape"
            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=".Begin"
            android:screenOrientation="landscape"
            android:label="@string/app_name" 
            >
          <intent-filter>
                  <action android:name="begingame" />
                  <category android:name="android.intent.category.DEFAULT" />
          </intent-filter>
        </activity>

        <activity
            android:name=".Sushitap"
            android:screenOrientation="landscape"
            android:label="@string/app_name" >

        <intent-filter>
                <action android:name="gameover" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

4

6 回答 6

1

输入 EditText 后 ENTER KEY PRESSED 时,使用View.OnKeyListener for EditText 从 EditText 中删除焦点:

ditText.setOnKeyListener(onSoftKeyboardDonePress);

    private View.OnKeyListener onSoftKeyboardDonePress=new View.OnKeyListener() 
    {
        public boolean onKey(View v, int keyCode, KeyEvent event) 
        {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)
            {
                 // code to hide the soft keyboard
                 EditTexst.clearFocus();
                 EditTexst.requestFocus(EditText.FOCUS_DOWN);            
            }
            return false;
        }
    };
于 2012-06-29T10:20:25.957 回答
0

您需要将 xml 中的 edittext 链接到您的代码。在您的 oncreate 方法中添加

EditText edittext= (EditText ) findViewById(R.id.editText2);
于 2012-06-29T10:22:22.657 回答
0

您可以尝试将其放入edittext的布局文件中吗?

 android:focusableInTouchMode="true"
于 2012-06-29T10:23:43.227 回答
0

尝试这个。

editTextId.clearFocus();
editTextId.requestFocus(EditText.FOCUS_DOWN); // assuming that you want to move the focus to the next View Element. If you want it to go to the previous View, use FOCUS_UP
于 2012-06-29T10:15:24.263 回答
0

如果您的应用程序需要编辑文本和旁边的图像视图..那么这是您可以使用的代码。在 layout.xml 中,您可以将此代码添加到带有图像的 edittext

<LinearLayout        
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white2" >


    <EditText
        android:id="@+id/et_search"
        android:layout_width="280dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="5dp"
        android:drawableRight="@drawable/search_20"
        android:ems="10"
        android:hint="@string/search_brdNm" />

</LinearLayout>

在您的 java 类中,您可以使用以下代码:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.search_asset);

        mEt_search = (EditText) findViewById(R.id.et_search);

    mEt_search.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String str_searchTxt = mEt_search.getText().toString().trim();
                String str_channelNm = AppConfigurationUtils.getChannelName();
                if (str_searchTxt.length() == 0) {
                    Toast.makeText(getApplicationContext(),
                            getResources().getString(R.string.ENTER_MANDATORY),
                            Toast.LENGTH_LONG).show();
                    return;
                }

            }
        });
}
于 2012-06-29T10:40:34.147 回答
0

大家好我的问题解决了!!!实际上,我正在从其他视图移动到该视图,在第一个视图中,我通过其布局 Id 调用当前类活动,因此在这种情况下,图像视图的行为不是普通按钮,而只是一个视图

所以在第一个视图中,我使用了一个意图来调用我在上面发布的活动的类,这成功地完成了我的任务!!!

谢谢大家的时间和努力......非常感谢!!!!

谢谢你!!!

于 2012-06-29T12:30:49.117 回答