一段为学自动化而写的代码

为学习android自动化测试而编写的一段代码,留着以后练习用:

package com.calculator.andyguo;


import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


public class Calculator extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
final String LOG_TAG = "MainScreen";
super.onCreate(savedInstanceState);
setContentView(R.layout.main);


final EditText value1 = (EditText) findViewById(R.id.value1);
final EditText value2 = (EditText) findViewById(R.id.value2);


final TextView result = (TextView) findViewById(R.id.result);


Button addButton = (Button) findViewById(R.id.addValues);
addButton.setOnClickListener(new OnClickListener() {


public void onClick(View v) {
try {
int val1 = Integer.parseInt(value1.getText().toString());
int val2 = Integer.parseInt(value2.getText().toString());
Integer answer = val1 + val2;
result.setText(answer.toString());
Toast.makeText(Calculator.this,answer.toString(),Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(LOG_TAG, "加法计算错误!", e);
}
}
});


Button multiplyButton = (Button) findViewById(R.id.multiplyValues);
multiplyButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
int val1 = Integer.parseInt(value1.getText().toString());
int val2 = Integer.parseInt(value2.getText().toString());
Integer answer = val1 * val2;
result.setText(answer.toString());
Toast.makeText(Calculator.this,answer.toString(),Toast.LENGTH_LONG).show();
} catch (Exception e) {
Log.e(LOG_TAG, "乘法计算错误!", e);
}
}
});

ListView listView = (ListView)findViewById(R.id.mylist);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(Calculator.this, android.R.layout.simple_list_item_1, android.R.id.text1, new String[]{"a","b"});
listView.setAdapter(adapter);

ListView listView1 = (ListView)findViewById(R.id.mylist0);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(Calculator.this, android.R.layout.simple_list_item_1, android.R.id.text1, new String[]{"a","b"});
listView1.setAdapter(adapter1);
}
}




<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<TextView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
android:gravity="center_horizontal"
android:textSize="48px"
android:padding="12px" />
<EditText
android:layout_height="wrap_content"
android:id="@+id/value1"
android:hint="@string/hint1"
android:maxLength="6"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:textSize="20px">
</EditText>

<EditText
android:layout_height="wrap_content"
android:id="@+id/value2"
android:maxLength="6"
android:hint="@string/hint2"
android:inputType="numberDecimal"
android:layout_width="fill_parent"
android:textSize="20px">
</EditText>
<FrameLayout
android:id="@+id/FrameLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3px"
android:background="#ff0000">
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#000000"
android:padding="1px">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/resultLabel"
android:textSize="25px"
android:id="@+id/resultLabel">
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/result"
android:textSize="25px"
android:textStyle="bold"
android:layout_marginLeft="16px">
</TextView>
</LinearLayout>
</FrameLayout>
<LinearLayout
android:id="@+id/LinearLayout03"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="@+id/addValues"
android:text="@string/add"
android:textSize="32px">
</Button>
<Button
android:layout_height="wrap_content"
android:id="@+id/multiplyValues"
android:text="@string/multiply"
android:textSize="32px"
android:layout_width="wrap_content">
</Button>
</LinearLayout>

<ListView android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/mylist" ></ListView>

<ListView android:layout_height="fill_parent"
android:layout_width="wrap_content"
android:id="@+id/mylist0" ></ListView>
</LinearLayout>
</LinearLayout>

你可能感兴趣的:(自动化)