when i install this apk,the activity shows,but it doesn't execute any behind code.
I think there is something wrong in my AndroidMainfest.xml.But where?
this is my AndroidMainfest.xml:
="1.0"="utf-8"
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.notepad"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.notepad.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
this is activmainity_.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.example.notepad.MainActivity$PlaceholderFragment" >
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:inputType="text"
android:ems="10" >
<requestFocus />
</EditText>
<Button
android:id="@+id/Add"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText"
android:layout_alignBottom="@+id/editText"
android:layout_alignParentRight="true"
android:text="@string/addText" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editText"
android:layout_alignRight="@+id/Add"
android:layout_below="@+id/editText"
android:layout_marginTop="43dp"
android:text="@string/showText" />
</RelativeLayout>
this is MainActivity.java(behind behand)
package com.example.notepad;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
@SuppressLint("ShowToast")
public class MainActivity extends ActionBarActivity {
@SuppressLint("ShowToast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toast.makeText(this,".在创建时",1000);
Button iButton=(Button)findViewById(R.id.Add);
iButton.setOnClickListener(new View.OnClickListener() {
@SuppressLint("ShowToast")
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), ".在点击时",1000);
try {
toSaveAndShow();
Toast.makeText(getApplicationContext(),".在Try完成后",1000);
} catch (IOException e) {
e.printStackTrace();
}
}
});
Toast.makeText(this, ".在新方法调用时",1000);
File myFile=new File("data.txt");
if(myFile.exists()!=true){
try {
myFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
Date myDate=new Date();
OutputStream out = new FileOutputStream(myFile,true);
EditText youSay=(EditText)findViewById(R.id.editText);
byte[] bufferByte=new byte[youSay.getText().length()+1];
bufferByte=youSay.getText().toString().getBytes();
out.write(bufferByte);
String inStr="\t"+myDate.getDate();
byte[] systemInfo=inStr.getBytes();
out.write(systemInfo);
out.close();
TextView myView=(TextView)findViewById(R.id.textView);
myView.setText(youSay.getText().toString()+inStr);
youSay.setText("");
Toast.makeText(this, ".我完成了",1000);
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, ".出错了!",1000);
} catch (IOException e) {
e.printStackTrace();
}
}
protected void saveFile(){
Button iButton=(Button)findViewById(R.id.Add);
iButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Toast.makeText(getApplicationContext(), ".在点击时",1000);
try {
toSaveAndShow();
Toast.makeText(getApplicationContext(),".在Try完成后",1000);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
private void toSaveAndShow() throws IOException {
Toast.makeText(this, ".在新方法调用时",1000);
File myFile=new File("data.txt");
if(myFile.exists()!=true){
myFile.createNewFile();
}
try {
Date myDate=new Date();
OutputStream out = new FileOutputStream(myFile,true);
EditText youSay=(EditText)findViewById(R.id.editText);
byte[] bufferByte=new byte[youSay.getText().length()+1];
bufferByte=youSay.getText().toString().getBytes();
out.write(bufferByte);
String inStr="\t"+myDate.getDate();
byte[] systemInfo=inStr.getBytes();
out.write(systemInfo);
out.close();
TextView myView=(TextView)findViewById(R.id.textView);
myView.setText(youSay.getText().toString()+inStr);
youSay.setText("");
Toast.makeText(this, ".我完成了",1000);
} catch (FileNotFoundException e) {
e.printStackTrace();
Toast.makeText(this, ".出错了!",1000);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
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_main, container,
false);
return rootView;
}
}
}