玩转FPGA山寨版

看了《玩转FPGA》,写的不错,写写山寨版和大家交流!

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
View Code
<?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"
>
<Button
android:id="@+id/button1"
android:layout_width
="fill_parent"
android:layout_height
="wrap_content"
android:text
="@string/button1"
/>
</LinearLayout>

View Code
package com.Neddy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends Activity
{
private Button button=null;
private final static int REQUEST_CODE=1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button
=(Button)findViewById(R.id.button1);
button.setOnClickListener(listener);
}

private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
// Intent intent=new Intent();
// intent.setAction(Intent.ACTION_SENDTO);
// intent.setData(Uri.parse("smsto:5554"));
// intent.putExtra("sms_body", "Welcome to ...");
// startActivity(intent);
Intent intent=new Intent();
intent.setClass(MainActivity.
this,SecondActivity.class);
intent.putExtra(
"str", "HI,hello world!");
// startActivity(intent);
startActivityForResult(intent, REQUEST_CODE);
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(requestCode==REQUEST_CODE)
{
if(resultCode==SecondActivity.RESULT_CODE)
{
Bundle bundle
=data.getExtras();
String str
=bundle.getString("back");
Toast.makeText(MainActivity.
this,str,Toast.LENGTH_LONG).show();
}

}
}

}
View Code
package com.Neddy;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class SecondActivity extends Activity
{
private TextView second=null;
private Button button2=null;
final static int RESULT_CODE=1;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.second);
Intent intent
=getIntent();
Bundle bundle
=intent.getExtras();
String str
=bundle.getString("str");
second
=(TextView)findViewById(R.id.second);
second.setText(str);

button2
=(Button)findViewById(R.id.button2);

button2.setOnClickListener(listener);

}

private OnClickListener listener=new OnClickListener()
{
public void onClick(View v)
{
Intent intent
=new Intent();
intent.putExtra(
"back", "Back Data");
setResult(RESULT_CODE,intent);
finish();
}
};

}
View Code
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package
="com.Neddy"
android:versionCode
="1"
android:versionName
="1.0">
<uses-sdk android:minSdkVersion="8" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".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>
<activity android:name=".SecondActivity"
android:label
="Second">
</activity>

</application>
<uses-permission android:name="android.permission.SEND_SMS"/>
</manifest>

posted on 2011-09-10 10:06  Neddy11  阅读(226)  评论(0编辑  收藏  举报