參考網址http://sukelven.pixnet.net/blog/post/53825727
package fcu.edu;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String[] vData = {"星期一","星期二","星期三","星期四","星期五","星期六","星期日",};
ListView lv = new ListView(this);
lv.setChoiceMode( ListView.CHOICE_MODE_MULTIPLE );
ArrayAdapter arrayAdapter2 = new ArrayAdapter(this,
android.R.layout.simple_list_item_multiple_choice, vData);
ArrayAdapter arrayAdapter = arrayAdapter2;
ArrayAdapter vArrayData = arrayAdapter;
lv.setAdapter( vArrayData );
setContentView(lv);
}
}
2011年6月16日 星期四
JAVA期末自製
package fcu.edu;
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 add extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText fromNumber = (EditText)this.findViewById( R.id.fromNumber );
final EditText toNumber = (EditText)this.findViewById( R.id.toNumber );
Button equals = (Button)this.findViewById( R.id.equals );
final TextView totalValue = (TextView)this.findViewById( R.id.totalValue );
equals.setOnClickListener(new OnClickListener
(){
public void onClick(View v) {
try {
int fromNum = Integer.parseInt(fromNumber.getText().toString());
int toNum = Integer.parseInt(toNumber.getText().toString());
totalValue.setText( fromNum + toNum + "" );
}catch( Exception e )
{
totalValue.setText("請輸入正確的數字型態 !! ");
}
}
});
}
}
<?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="@string/hello"
/>
<EditText android:id="@+id/fromNumber"
android:layout_width="149px"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="10px"
android:layout_y="32px"
/>
<TextView android:id="@+id/widgetAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textSize="20sp"
android:layout_x="10px"
android:layout_y="82px"
/>
<EditText android:id="@+id/toNumber"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="10px"
android:layout_y="112px"
/>
<Button android:id="@+id/equals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:textSize="20sp"
android:layout_x="10px"
android:layout_y="172px"
/>
<TextView android:id="@+id/totalValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="#ffffff00"
android:layout_x="10px"
android:layout_y="232px"
/>
</LinearLayout>
輸入正確數字會相加
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 add extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText fromNumber = (EditText)this.findViewById( R.id.fromNumber );
final EditText toNumber = (EditText)this.findViewById( R.id.toNumber );
Button equals = (Button)this.findViewById( R.id.equals );
final TextView totalValue = (TextView)this.findViewById( R.id.totalValue );
equals.setOnClickListener(new OnClickListener
(){
public void onClick(View v) {
try {
int fromNum = Integer.parseInt(fromNumber.getText().toString());
int toNum = Integer.parseInt(toNumber.getText().toString());
totalValue.setText( fromNum + toNum + "" );
}catch( Exception e )
{
totalValue.setText("請輸入正確的數字型態 !! ");
}
}
});
}
}
<?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="@string/hello"
/>
<EditText android:id="@+id/fromNumber"
android:layout_width="149px"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="10px"
android:layout_y="32px"
/>
<TextView android:id="@+id/widgetAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="+"
android:textSize="20sp"
android:layout_x="10px"
android:layout_y="82px"
/>
<EditText android:id="@+id/toNumber"
android:layout_width="150px"
android:layout_height="wrap_content"
android:text=""
android:textSize="18sp"
android:layout_x="10px"
android:layout_y="112px"
/>
<Button android:id="@+id/equals"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="="
android:textSize="20sp"
android:layout_x="10px"
android:layout_y="172px"
/>
<TextView android:id="@+id/totalValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textColor="#ffffff00"
android:layout_x="10px"
android:layout_y="232px"
/>
</LinearLayout>
輸入正確數字會相加
不是輸入數字會要求重新輸入
訂閱:
文章 (Atom)