我正在开发头脑中的第一个进入android开发的练习 并按照指定的书完成练习,但键入R.id.chooser表示,即使我在字符串XML中声明了选择符号,也无法进行重新分配。这很奇怪......有没有人建议解决这个问题?
java文件:
package com.hfad.messenger;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;`enter code here`
import android.content.Intent;
import android.widget.EditText;
public class CreateMessageActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_message);
}
//Call onSendMessage() when the button is clicked
public void onSendMessage(View view) {
EditText messageView = (EditText)findViewById(R.id.message);
String messageText = messageView.getText().toString();
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/pain");
intent.putExtra(Intent.EXTRA_TEXT, messageText);
String chooserTitle = getString(R.string.chooser);
Intent chosenIntent = Intent.createChooser(intent, chooserTitle);
startActivity(chosenIntent);
}
}
xml文件:
<resources>
<string name="app_name">Messenger</string>
<string name="send">Send Message</string>
<String name="chooser">Send Message...</String>
<string name="action_settings">Settings</string>
<string name="title_activity_receive_message">ReceiveMessageActivity</string>
</resources>
答案 0 :(得分:0)
您认为您已使用大写的第一个字母chooser
宣布String
,但它应该像string
一样:
<resources>
<string name="app_name">Messenger</string>
<string name="send">Send Message</string>
<string name="chooser">Send Message...</string>
<string name="action_settings">Settings</string>
<string name="title_activity_receive_message">ReceiveMessageActivity</string>
</resources>
这就是为什么Android Studio无法找到chooser
字符串。