samedi 27 juin 2015

(Android-intent) How do I fix the string R.id.chooser so that it is referenced by the java file

I was working on the excercise in the book Head first in to android development and did the exercise as precisely the book specified, but typing R.id.chooser says chooser symbol cannot be resoled even though i declared it in strings XML. This is weird... anyone have suggestions to fix this?

java file:

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 file:

<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>

Aucun commentaire:

Enregistrer un commentaire