Direct data transfer activity

All data in the software can not be on the same page or processed in the same class, which involves the transmission of data directly in the web in the future after the data to be passed to the data processing field is passed through the form form Android directly in the transmission of data through the Bundle the data down to the stack for data transfer, then. getIntent (). getExtras () to get to the inside of the data, the following is a simple transfer of data between. First place in the first two EditView an activity and then the user through the input data and spread to the other two in an activity and then calculate and display the results of two numbers define the first two EditView in main.xml and a Button
<? 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"
>
<TextView
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: text = "calculated data"
/>
<EditText
android: id = "@ + id/data1"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
/>
<EditText
android: id = "@ + id/data2"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
/>
<Button
android: id = "@ + id / button"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: text = "Computing"
/>
</ LinearLayout>
Create the first activity class
package com.data;

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.EditText;

public class ActivityData extends Activity {
/ ** Called when the activity is first created. * /

private Button button;

@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
button = (Button) findViewById (R.id.button);

button.setOnClickListener (new OnClickListener () {

public void onClick (View v) {

EditText data1 = (EditText) findViewById (R.id.data1);
EditText data2 = (EditText) findViewById (R.id.data2);
Intent intent = new Intent ();
Bundle bundle = new Bundle ();

bundle.putString ("value1", data1.getText (). toString ());
bundle.putString ("value2", data2.getText (). toString ());

intent.putExtras (bundle);
intent.setClass (ActivityData.this, ResultActivity.class);
startActivity (intent);
ActivityData.this.finish ();
}
});
}
}
And the user-entered data on the Bundle Intent to pass through to another activity
Also in the layout folder in which to create a mylayout.xml configuration file to add a label with a display EditView shows the results
<? Xml version = "1.0" encoding = "utf-8"?>
<LinearLayout
xmlns: android = "http://schemas.android.com/apk/res/android"
android: layout_width = "fill_parent"
android: layout_height = "fill_parent">

<TextView
android: id = "@ + id / result"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
/>

</ LinearLayout>
Create another to receive data activity
package com.data;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class ResultActivity extends Activity {

@ Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.mylayout);

Bundle bundle = this.getIntent (). GetExtras ();

Double data1 = Double.parseDouble (bundle.getString ("value1"));
Double data2 = Double.parseDouble (bundle.getString ("value2"));

Double result = data1 + data2;
TextView textView = (TextView) findViewById (R.id.result);
textView.setText ("result ========" + result);
}

}
Activity for the first pass over the data to calculate and display the results in AndroidManifest.xml registered activity
<? Xml version = "1.0" encoding = "utf-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
package = "com.data"
android: versionCode = "1"
android: versionName = "1.0">
<uses-sdk android:minSdkVersion="4" />

<application android:icon="@drawable/icon" android:label="@string/app_name">
<Activity android: name = ". ActivityData"
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=".ResultActivity"> </ activity>
</ Application>
</ Manifest>
Results of the implementation plans

Direct data transfer activity

Direct data transfer activity

分类:Industry 时间:2011-09-19 人气:136
分享到:
blog comments powered by Disqus

相关文章

  • FLEX read xml with a xmlns namespace 2011-09-28

    With the XML namespace <?xml version="1.0" encoding="UTF-8"?> <root version="1" xmlns="http://xspf.org/ns/0/"> <users> <user> <user_name name="zzz"> Joe Smith </user_name&g

  • Code records (XML documents on a regular scan and insert the data table) 2011-01-05

    Sorry, you Tell me, this is for their own look, not many comments. <? Php include ('/ jtxm / web / config / config.php'); / / Root directory $ Root = '/ jtxm / server /'; $ PetDir = '/ common / item / xml /'; / / Update the pet name of the log $ PetN

  • Jdom create XML file persistent data, program data to disk 2010-05-12

    Theme Description: This article details how to use the JAVA Jdom the org.jdom.output package XMLOutputter Format class with class and create a XML file data in program Requirements: Process is a list writeXml collection, save a number of "① students

  • Use custom connection. For xml path ('') and the stuff displays multiple lines of data to merge row 2010-10-27

    -- Use custom connection .for xml path('') And the stuff that displays multiple lines of data to the combined line -- Note --1. Computed column can not contain aggregate functions directly in displays, such as the following statement val. --2.for xml

  • JAXB: Use annotation binding XML (xmlns) 2010-06-29

    Java development in the use of XML almost every programmer will encounter, we choose the database currently available, there are many, including, dom4j, jaxen, SAX, etc. This article describes how to use JAXB to Object-XML mapping. JAXB is currently

  • oracle xml notes four operating 2010-09-07

    Use fn: doc and fn: collection function in the XML DB repository to query XML data There are two important XQuery functions that can be used to query the XML DB repository for all resources. Fn: doc is an XQuery function that can access the repositor

  • ajax input prompt implementation 2009-03-07

    Projects have used at the time entered by the user to give some tips, suggesting that the contents are extracted from the database (in Chinese). So a google search under the amended part of their code to share with you. Attachment is available at the

  • Xiang Jie Struts configuration file, web.xml and struts-cofig.xml, as well as the struts-cofig.xml in the role of the various labels 2010-04-19

    Struts applications use two XML-based configuration files to configure, respectively web.xml and struts-cofig.xml file. Web.xml file is the configuration for all web applications, while the struts-config.xml file is struts-specific configuration file

  • I am bitter jquery + js + xml + servlet + jsp (html) experience 2010-08-07

    <% @ Page language = "java" import = "java.util .*" pageEncoding = "utf-8"%> <% String path = request.getContextPath (); String basePath = request.getScheme ()+"://"+ request.getServerName ()+":"+

  • struts-config.xml file description element 2010-08-08

    Struts application uses two XML-based configuration files to configure, namely web.xml and struts-cofig.xml file. Web.xml file is the configuration for all web applications, while the struts-config.xml file is struts-specific configuration file, can

iOS 开发

Android 开发

Python 开发

JAVA 开发

开发语言

PHP 开发

Ruby 开发

搜索

前端开发

数据库

开发工具

开放平台

Javascript 开发

.NET 开发

云计算

服务器

Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 黔ICP备15002463号-1

processed in 0.327 (s). 12 q(s)