简体   繁体   English

如何在Toast消息框中显示string []值?

[英]How to display string[] value in Toast Message Box?

I am new to Android Environment.I have to display Toast message box using the String[] value.But the Toast message Syntax cannot accept the String[] value.How can i display message the String[] value by Using Toast.The Toast can accept the CharSequence only.how can i change the String[] value into CharSequence? 我是Android环境的新手。我必须使用String []值显示Toast消息框。但是Toast消息语法不能接受String []值。如何使用Toast显示消息String []值。只能接受CharSequence。如何将String []值更改为CharSequence?

Here i am using this code to display String[] Value: 在这里,我正在使用此代码显示String []值:

 public static String[] sysid1;
 sysid1= PerformCommand(inCmd,"","",m_SystemID, m_Username,m_Password,m_Data);
 Toast toast=Toast.makeText(EpicClub.this,sysid1,Toast.LENGTH_SHORT);
toast.show()

Convert the String array to string using : 使用以下命令将String数组转换为字符串:

String sysid1String = Arrays.toString(sysid1)  

and then pass sysid1String it as argument to Toast.makeText 然后将sysid1String作为参数传递给Toast.makeText

like this 像这样

Toast.makeText(getApplicationContext(),sysid1String ,Toast.LENGTH_SHORT).show();

You can output a String using a Toast. 您可以使用Toast输出字符串。 What you're trying to do is output an Array of Strings. 您想要做的是输出一个字符串数组。

Depending on what you want to output either concatenate the Strings, or select the String at your required index and select that for output. 根据要输出的内容,连接字符串,或在所需索引处选择字符串,然后选择要输出的字符串。

you have to use like: 您必须使用像:

String[] sysid1 = {"a","b"};  

Toast.makeText(MainActivity.this, ""+Arrays.toString(sysid1), Toast.LENGTH_SHORT).show(); 

Suppose you have array of strings as below. 假设您具有如下所示的字符串数组。 You can use the array index to display the toast. 您可以使用数组索引显示吐司。

 public static String[] sysid1={"hello","hi"};
 Toast toast=Toast.makeText(this,sysid1[0],Toast.LENGTH_SHORT);
 toast.show(); 

Instead of string array you can use a arraylist 代替字符串数组,您可以使用arraylist

   ArrayList<String> al = new ArrayList<String>();
   al.add("hello");
   al.add("hi");
   Toast toast=Toast.makeText(this,al.get(0),Toast.LENGTH_SHORT);// use the index to get the string
   toast.show();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM