I have been using Android Studio to create my first app. I am not using another IDE, Having gone thought the exercise I have reached errors in the following areas.
- My Activity
- Display Message Activity
- Gradle
DisplayMessageActivity
`package com.company.myfirstapp; import android.annotation.TargetApi; import android.os.Build; import static android.os.Build.*; /** * Created by MyActivity on 17/10/2015. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the message from the intent Intent intent = getIntent(); String message = intent.getStringExtra(MyActivity.EXTRA_MESSAGE); // Create the text view TextView textView = new TextView(this); textView.setTextSize(40); textView.setText(message); // Set the text view as the activity layout setContentView(textView); }`
MyActivity
`package com.company.myfirstapp; import android.content.Intent; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.EditText; import com.company.myfirstapp.DisplayMessageActivity; import com.company.myfirstapp.R; public class MyActivity extends AppCompatActivity { final public static String EXTRA_MESSAGE = "com.company.myfirstapp.MESSAGE"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_my, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } Intent intent = new Intent(this, DisplayMessageActivity.class); EditText editText = (EditText) findViewById(R.id.edit_message); String message = editText.getText().toString(); intent.putExtra(EXTRA_MESSAGE, message); MyActivity.this.startActivity(intent); } }
}`
Ap
apply plugin: 'com.android.application' final def extension = android { compileSdkVersion 22 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.company.myfirstapp" minSdkVersion 8 targetSdkVersion 22 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } final def extension1 = extension extension1 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' }
My First App
// Top-level build file where you can add configuration options common to `all sub-projects/modules. buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.2.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() }
}`
I have errors on Override and public void in Display Message Activity and Display Message in My Activity.
No comments:
Post a Comment