chào bạn dalvik, tôi thấy bạn hỏi câu hỏi này trên diễn đàn android.vn rất lâu và nhiều lần nửa. hôm nay tôi bỏ ra một chút thời gian để làm 1 ứng dụng như yêu cầu của bạn.
toàn bộ source code bạn cần ở phía dưới:
file activity_main.xml
Mã:
<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=".mainactivity" >
<textview
android:id="@+id/textview1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignparenttop="true"
android:layout_centerhorizontal="true"
android:text="tổng 2 số"
android:textappearance="?android:attr/textappearancelarge" />
<textview
android:id="@+id/textview2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textview1"
android:layout_margintop="15dp"
android:text="số thứ nhất:"
android:textappearance="?android:attr/textappearancemedium" />
<edittext
android:id="@+id/edittext_soa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignparentleft="true"
android:layout_below="@+id/textview2"
android:ems="10"
android:inputtype="numberdecimal" >
<requestfocus />
</edittext>
<textview
android:id="@+id/textview3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignleft="@+id/edittext_soa"
android:layout_below="@+id/edittext_soa"
android:text="số thứ hai:"
android:textappearance="?android:attr/textappearancemedium" />
<edittext
android:id="@+id/edittext_sob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignleft="@+id/textview3"
android:layout_below="@+id/textview3"
android:layout_margintop="14dp"
android:ems="10"
android:inputtype="numberdecimal" />
<textview
android:id="@+id/textview4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignleft="@+id/edittext_sob"
android:layout_below="@+id/edittext_sob"
android:text="kết quả:"
android:textappearance="?android:attr/textappearancemedium" />
<edittext
android:id="@+id/edittext_kq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignleft="@+id/textview4"
android:layout_below="@+id/textview4"
android:layout_margintop="16dp"
android:ems="10"
android:inputtype="numberdecimal" />
<button
android:id="@+id/button_tinh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/edittext_kq"
android:layout_centerhorizontal="true"
android:layout_margintop="25dp"
android:text="tính tổng 2 số" />
</relativelayout>
file mainactivity.java
Mã:
package tong2so.v1;
import android.os.bundle;
import android.app.activity;
import android.view.menu;
import android.view.view;
import android.view.view.onclicklistener;
import android.widget.button;
import android.widget.edittext;
public class mainactivity extends activity
{
edittext et_a, et_b, et_kq;
button btn_tinh;
@override
protected void oncreate(bundle savedinstancestate)
{
super.oncreate(savedinstancestate);
setcontentview(r.layout.activity_main);
et_a=(edittext) findviewbyid(r.id.edittext_soa);
et_b=(edittext) findviewbyid(r.id.edittext_sob);
et_kq=(edittext) findviewbyid(r.id.edittext_kq);
btn_tinh=(button) findviewbyid(r.id.button_tinh);
btn_tinh.setonclicklistener(new onclicklistener()
{
@override
public void onclick(view arg0)
{
float kq=float.parsefloat(et_a.gettext().tostring())+
float.parsefloat(et_b.gettext().tostring());
et_kq.settext(string.valueof(kq));
}
});
}
@override
public boolean oncreateoptionsmenu(menu menu)
{
// inflate the menu; this adds items to the action bar if it is present.
getmenuinflater().inflate(r.menu.main, menu);
return true;
}
}
thân chào bạn.
Trong thế giới coi ngó sức khỏe dục tình đương đại, mát xa tuyến tiền liệt không còn là điều xa lạ. Nó không chỉ mang lại khoái cảm sâu sắc mà còn tương trợ nam giới cải thiện sức khỏe sinh lý và...
Dụng cụ mát xa tiền liệt tuyến Svakom Vick: Lựa chọn cho nam giới