gpt4 book ai didi

java - 类型 View 的 setText 方法字符串未定义

转载 作者:行者123 更新时间:2023-12-01 07:29:34 25 4
gpt4 key购买 nike

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

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

最佳答案

尝试改变这一点:

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

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

关于java - 类型 View 的 setText 方法字符串未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19199946/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com