首页 > 解决方案 > 制作使用 java 类 .contains 的吐司不起作用

问题描述

我正在尝试制作 android 应用程序,显示链接是否包含 https 并且不起作用(在编辑代码后没有 toast 出现)我认为使用 '. contains()'... 我可以在这些方面寻求帮助吗?这些是用 java 编写的,并在 android 7.0 环境中进行了测试。

 package com.example.messengerandroid7;

import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.app.AlertDialog;


public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Button button;
        TextView resultLabel;
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = findViewById(R.id.button);
        resultLabel = findViewById(R.id.resultLabel);

        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                class indexOf {
                    class contains {
                        public void main(String[] args) {
                            EditText url = findViewById(R.id.url);
                            String urlname = url.getText().toString();
                            Log.v(urlname, "test");
                            if (urlname.contains("https")) {
                                Toast.makeText(MainActivity.this, "xxxxxx", Toast.LENGTH_LONG).show();
                            } else {
                                Toast.makeText(MainActivity.this, "ㅇㅇㅇㅇㅇ", Toast.LENGTH_LONG).show();
                            }
                        }
                    }
                }
            }
        });
    }
}

标签: javaandroid

解决方案


推荐阅读