0

我是 android 新手,有创建电子邮件应用程序的任务。所以我有 2 个布局和 2 个活动,一个用于阅读电子邮件,一个用于编写电子邮件。我正在尝试保留在电子邮件写作活动的字段中发送的信息,以供阅读电子邮件时使用。问题出在下面的 ** 粗体行 - “类型视图的方法 setText 字符串未定义”,我需要获取所有文本视图以包含从其他活动发送的信息。如果需要,我可以发布其他文件,感谢所有帮助。我尝试了其他方法将变量分配给文本视图,但似乎无法让它工作。

DisplayMessageActivity.java

    package com.example.project;

    import com.example.project.R.layout;

    import android.annotation.TargetApi;
    import android.app.Activity;
    import android.content.Intent;
    import android.os.Build;
    import android.os.Bundle;
    import android.support.v4.app.NavUtils;
    import android.view.MenuItem;
    import android.widget.TextView;

    public class DisplayMessageActivity extends Activity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_message);
        // Show the Up button in the action bar.
        setupActionBar();

        // Get the messages from the intent
        Intent intent = getIntent();
        String messageto2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
        String messagefrom2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE2);
        String messagecc2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE3);
        String messagebcc2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE4);
        String messagesubject2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE5);
        String messagebody2 = intent.getStringExtra(MainActivity.EXTRA_MESSAGE6);



        **TextView msgto = (TextView)findViewById(R.id.to2).setText(messageto2);**
        TextView msgfrom = (TextView)findViewById(R.id.from2);
        TextView msgcc = (TextView)findViewById(R.id.cc2);
        TextView msgbcc = (TextView)findViewById(R.id.bcc2);
        TextView msgsubject = (TextView)findViewById(R.id.subject2);
        TextView msgbody = (TextView)findViewById(R.id.body2);



    }

    /**
     * Set up the {@link android.app.ActionBar}, if the API is available.
     */
    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    private void setupActionBar() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
            getActionBar().setDisplayHomeAsUpEnabled(true);
        }
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            // This ID represents the Home or Up button. In the case of this
            // activity, the Up button is shown. Use NavUtils to allow users
            // to navigate up one level in the application structure. For
            // more details, see the Navigation pattern on Android Design:
            //
            // http://developer.android.com/design/patterns/navigation.html#up-vs-back
            //
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
        return super.onOptionsItemSelected(item);
        }

     }

TIA

4

4 回答 4

4

尝试改变这一点:

(TextView)findViewById(R.id.to2).setText(messageto2);

((TextView)findViewById(R.id.to2)).setText(messageto2);
于 2013-10-05T16:24:45.747 回答
1

尝试这个..

((TextView)findViewById(R.id.to2)).setText(messageto2);
于 2013-10-05T16:25:02.357 回答
1

根据引用的静态类型解析方法。findViewById()以返回类型声明,View并且由于该类View未声明方法setText(),因此编译器会抱怨。用这个

TextView msgto = (TextView)findViewById(R.id.to2);
msgto.setText(messageto2);
于 2013-10-05T16:25:31.360 回答
1
TextView msgto = (TextView)findViewById(R.id.to2).setText(messageto2);

需要改为

TextView msgto = (TextView) findViewById(R.id.to2);
msgto.setText(messageto2);

那应该有帮助。

于 2013-10-05T16:29:08.640 回答