1

アプリの作成画面を作成しています。ユーザーがメッセージを入力する場所と、ステータスに画像が添付されてScrollViewいるかどうかに応じて表示のオンとオフが切り替えられる です。これが私のレイアウト XML の一部です。RelativeViewEditTextImageView

<!-- @dimen/bigGap = 8dp -->
<ScrollView android:id="@+id/parentScrollView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_marginTop="@dimen/bigGap"
    android:layout_marginRight="@dimen/bigGap"
    android:layout_marginLeft="@dimen/bigGap"
    android:layout_marginBottom="@dimen/bigGap"
    android:layout_above="@+id/footer"
    android:background="#006400"
    > <!-- green background color -->

    <RelativeLayout android:id="@+id/parentLinearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFD700"> <!-- yellow background color -->

        <EditText android:id="@+id/postText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#dddddd"
            android:inputType="textMultiLine"
            android:gravity="top|left"
            /> <!-- gray background color -->

        <ImageView android:id="@+id/postImage"
            android:layout_width="@dimen/thumbnailSize"
            android:layout_height="@dimen/thumbnailSize"
            android:visibility="gone"
            android:layout_below="@id/postText"
            />
    </RelativeLayout>
</ScrollView>

myEditTextの高さはであるため、全体は黄色の背景 ( の緑色の背景を完全に覆う) の上wrap_contentに灰色の背景 ( ) の 1 行で始まります。ただし、後ですべてのビューの背景を白に変更し (単一のコンポーネントのように見せるため)、ユーザーがその 1 行だけをタップしてキーボードをポップアップできるようにするのは直感に反します。 .EditTextRelativeLayoutScrollViewEditText

ここに画像の説明を入力

私がしたいのは、 のクリックおよびロング クリック アクションを のクリックおよびロング クリック アクションにリダイレクトすることですRelativeLayoutEditText、以下のコードは機能しません。ヘルプ?

final EditText editText = (EditText) findViewById(R.id.postText);
RelativeLayout rl = (RelativeLayout) findViewById(R.id.parentLinearLayout);
rl.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        Logger.d("onClick invoked!");
        editText.performClick();
    }
});
rl.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
        Logger.d("onLongClick invoked!");
        return editText.performLongClick();
    }
});

ここでの私の意図は、RelativeLayoutをクリックするとキーボードがポップアップし ( を実行した場合と同様EditText)、長押しすると切り取り/コピー/貼り付け/テキスト選択オプションが表示されるようにすることです ( と同じ動作EditText)。

4

2 に答える 2

1

説明から、実際に欲しいのはキーボードを開くことです。したがって、質問のタイトルは、実際の問題ではなく、解決策を示唆しています。

これをクリック リスナーから (またはページを表示した直後に) 呼び出します。

  ((InputMethodManager) myActivity
            .getSystemService(Context.INPUT_METHOD_SERVICE))
            .toggleSoftInput(InputMethodManager.SHOW_FORCED,
                    InputMethodManager.HIDE_IMPLICIT_ONLY);

編集:あなたも呼び出す必要がありますeditText.requestFocus();(@Philは正しいです)が、私の経験からすると、キーボードを開くだけでは十分ではないため、上記の醜いコードも必要になります。

于 2013-05-02T14:13:06.420 に答える