I am developing a Mobile app for the first time
Environment : Eclipse Kepler, Java 1.7 Backend :
I have followed the following steps :
1) Installed Android SDK and run the Android SDK Manager, and installed the required files
2) Installed ADT Eclipse ADT Plugin : https://dl-ssl.google.com/android/eclipse
At this stage in some standard docs it said that you have to now create an AVD, the AVD icon was suppose to appear in my toolbar, but I couldnt find it anywhere.
Now, I am trying to develop my first app as shown on this site : http://developer.android.com/training/basics/firstapp/index.html
I am jus adding my code snippets as below for reference :
main.xml :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</LinearLayout>
strings.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My First App</string>
<string name="edit_message">Enter a message</string>
<string name="button_send">Send</string>
<string name="action_settings">Settings</string>
<string name="title_activity_main">MainActivity</string>
<string name="uploading">Uploading…</string>
<string name="hello_world">Hello world!</string>
<string name="title_activity_display_message">DisplayMessageActivity</string>
</resources>
AndroidManifest.xml :
<!-- <?xml version="1.0" encoding="utf-8" standalone="no"?> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.amazon.demo"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion ="20" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:allowBackup="true" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
</activity>
<activity
android:name=".DisplayMessageActivity"
android:label="@string/title_activity_display_message"
android:parentActivityName="com.amazon.demo.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.amazon.demo.MainActivity" />
</activity>
</application>
</manifest>
MainActivity.java
public class MainActivity extends ActionBarActivity {
public final static String EXTRA_MESSAGE = "com.amazon.demo.MESSAGE";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public void sendMessage(View view) {
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);
startActivity(intent);
}
}
activity_main.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.amazon.demo.MainActivity" >
<EditText android:id="@+id/edit_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/edit_message" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_send"
android:onClick="sendMessage" />
</LinearLayout>
DisplayMessageActivity.java :
public class DisplayMessageActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.activity_display_message);
// Get the message from the intent
Intent intent = getIntent();
String message = intent.getStringExtra(MainActivity.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);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.display_message, 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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() { }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_display_message,container, false);
return rootView;
}
}
}
activity_display_message.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.amazon.demo.DisplayMessageActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
Now unlike the My First App crashes when pressing a button I dnt have the fragment_main.xml and the fragment_display_message.xml anywhere in my project dir. Are these two files created on their own? Or do we have to separately create them?
Also have I installed all the prerequisites for developing the Android application correctly? I am not sure.
Also, in the DisplayMessageActivity.java it says : fragment_display_message cannot be resolved or is not a field
Hence I am not able to run the file either.
Please help. and sry for the long description.