类型不匹配:无法从void转换为Integer

时间:2014-03-20 06:37:07

标签: android alert

我将此t1作为文本视图。 我想将t1的值存储在一个变量中但是我得到了#34;类型不匹配:无法从void转换为Integer"错误

Integer res=t1.setText(Integer.toString(result));

5 个答案:

答案 0 :(得分:7)

答案 1 :(得分:1)

您可以使用它来查看值

t1.setText(Integer.toString(result));

String result= t1.getText().toString();

如果你想提醒结果:

new AlertDialog.Builder(this)
    .setTitle("result")
    .setMessage("this is your textview value : "+ result)
    .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            // you can do what you want when user press yes
        }
     })
    .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) { 
            //  you can do what you want when user press no
        }
     })
    .setIcon(R.drawable.ic_dialog_alert)
     .show();

答案 2 :(得分:1)

使用以下代码:

int value=Integer.valueOf(t1.getText.toString());

答案 3 :(得分:0)

你应该从t1获得价值,所以:

  

Integer res = Integer.toString(t1.getText()。toString()); //从textView获取数据

仅将数据放入textView:

  

t1.setText(Integer.toString(结果)); //它不会返回任何内容

答案 4 :(得分:0)

使用Integer.parseInt();别忘了用numberformatexception包含try Catch。

相关问题