0

我正在创建一个自定义哈希映射数组适配器。其中,当用户单击一个元素时,会弹出一个 AlertDialog,该用户可以看到他的消息,为此我正在使用此代码,

final AlertDialog.Builder alert = new AlertDialog.Builder(this);



    alert.setTitle("PassWord Protected Message");
            alert.setMessage("Please Enter The Password to See The Messages");

            // Set an EditText view to get user input 
            final EditText input = new EditText(this);
            alert.setView(input);

            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int whichButton) 
            {
        //  Editable value = input.getText();
             // Do something with value!
                String we=input.getText().toString();
            //  Toast.makeText(getApplicationContext(), we, Toast.LENGTH_SHORT ).show();
                if (we.equalsIgnoreCase("password"))
                {
                    try 
                    {
                        String[] splitted = smsList.get( pos ).split("\n"); 
                        String sender = splitted[0];

                        for ( int i = 1; i < splitted.length; ++i )
                        {
                           //some code here
                        }

                    } 
                    catch (Exception e) 
                    {
                        e.printStackTrace();
                    }

                }

            }
            });

            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int whichButton) {
                 // Canceled.
            }
            });

             alert.show();

AlertDialog将要求用户输入密码。然后用户将能够看到这些消息。但我收到错误,

String[] splitted = smsList.get( pos ).split("\n"); 

在此,我在 split 函数上遇到错误,错误是“方法 split(String) 未定义类型 HashMap”。

4

1 回答 1

0

You'll have to type cast the smsList to String

String[] splitted = ((String)smsList.get( pos )).split("\n"); 
于 2013-05-25T18:04:33.827 回答