.equals()不适用于Android的Emojicons

时间:2017-07-05 17:04:07

标签: java android arrays android-imageview android-event

我正在Android Studio中创建一个Android应用程序。

屏幕显示一个ImageView,它生成一个随机的emojicon(我使用了一个数组)。然后弹出键盘(实现第三方键盘),用户必须找到相同的表情符号。一旦用户找到了emojicon并单击它,它就会在EmojiconTextView中在屏幕上显示emojicon。然后,如果2个表情符号相同,它将显示“Well Done!”。

我正在使用这个库,以便在我的app ::

中使用emojicons
  

com.github.hani-momanii:超-表情符号:1.0

我认为问题可能出在我的MainActivity.java底部的'if语句'中。因为我正在检查ImageView是否等于EmojiconTextView,并且对象是不同的。但是,我怎么能把它写在可行的地方呢?

package com.rptest.phase3;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.Random;

import hani.momanii.supernova_emoji_library.Actions.EmojIconActions;
import hani.momanii.supernova_emoji_library.Helper.EmojiconEditText;
import hani.momanii.supernova_emoji_library.Helper.EmojiconTextView;

public class MainActivity extends AppCompatActivity {

View rootView;
EmojiconEditText emojiconEditText;
EmojiconTextView emojiconTextView;
ImageView emojiButton;
ImageView submitButton;
EmojIconActions emojIcon;
Button myButton;
ImageView myRandomImage;
Button checkButton;
TextView checkingText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    rootView = (RelativeLayout) findViewById(R.id.activity_main);
    emojiButton = (ImageView) findViewById(R.id.emoji_button);
    submitButton = (ImageView) findViewById(R.id.submit_button);
    emojiconEditText = (EmojiconEditText) findViewById(R.id.emojicon_edit_text);
    emojiconTextView = (EmojiconTextView) findViewById(R.id.emojicon_text_view);
    myButton = (Button) findViewById(R.id.myButton);
    myRandomImage = (ImageView) findViewById(R.id.myRandomImage);
    checkButton = (Button) findViewById(R.id.checkButton);
    checkingText = (TextView) findViewById(R.id.checkingText);
    emojIcon = new EmojIconActions(getApplicationContext(), rootView, emojiButton, emojiconEditText);
    emojIcon.ShowEmojicon();

    //shows what emotion user has selected
    submitButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String message = emojiconEditText.getText().toString();
            emojiconTextView.setText(message);
        }
    });

    //generates random emotion from list (array)
    myButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            int[] cards={R.drawable.emoji_1f600,R.drawable.emoji_1f004,R.drawable.emoji_1f6ac,R.drawable.emoji_1f3a1,R.drawable.emoji_1f3cb_1f3ff,R.drawable.emoji_1f3a9,R.drawable.emoji_0030};
            Random r = new Random();
            int n = r.nextInt(7);
            myRandomImage.setImageResource(cards[n]);
        }
    });

    //checks the emotion input with the emotion displayed
    checkButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (myRandomImage.equals(emojiconTextView)) {
                checkingText.setText("Well done!");
            }
        }
    });
 }

}

这是我的activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/activity_main"
    tools:context=".MainActivity">

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/emoji_button"
        android:src="@mipmap/smiley"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true" />

    <ImageView
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:id="@+id/submit_button"
        android:padding="4dp"
        android:src="@drawable/ic_action_send_now"
        android:layout_above="@+id/emojicon_edit_text"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="50dp" />

    <hani.momanii.supernova_emoji_library.Helper.EmojiconEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/emojicon_edit_text"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@+id/emoji_button"
        app:emojiconSize="28sp"
        android:layout_alignParentEnd="true" />

    <hani.momanii.supernova_emoji_library.Helper.EmojiconTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/emojicon_text_view"
        android:textColor="@android:color/black"
        android:textAppearance="@style/TextAppearance.AppCompat.Large"
        android:text="Emojicon Text View"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="26dp"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myRandomImage"
        android:layout_above="@+id/emojicon_text_view"
        android:layout_centerHorizontal="true"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/myButton"
        android:text="Generate Random!"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/checkButton"
        android:text="Check!"
        android:layout_below="@+id/myButton"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Checking..."
        android:id="@+id/checkingText"
        android:layout_below="@+id/checkButton"
        android:layout_centerHorizontal="true"/>

</RelativeLayout>

如果您需要有关此问题的更多信息,请告诉我们!

0 个答案:

没有答案