Не знаю актуально или нет. Но вот примерно так: Проекты то хоть создавать уже можете, и все туда скопировать. main. xml
| Код | <?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" android:orientation="vertical" >
<EditText android:id="@+id/EditText01" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number" android:maxLength="10" /> <EditText android:id="@+id/EditText02" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="number" android:maxLength="10" /> <Button android:id="@+id/button1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="+" android:textSize="30sp" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="" /> </LinearLayout>
|
Java код
| Код | import android.app.Activity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView;
public class DvaActivity extends Activity { int a, b, c; EditText Text1, Text2; TextView Text;
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);
Text = (TextView) findViewById(R.id.text); Text1 = (EditText) findViewById(R.id.EditText01); Text2 = (EditText) findViewById(R.id.EditText02);
final Button button1 = (Button) findViewById(R.id.button1); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
try { a = Integer.parseInt(Text1.getText().toString()); b = Integer.parseInt(Text2.getText().toString());
} catch (NumberFormatException e) { a = 0; b = 0; } c = a+b; Text.setText("Результат сложения = "+c); }
});
} }
|
|