计一划
界面代码
···
<ImageButton
android:id="@+id/imagePlanBack"
android:layout_width="80dp"
android:layout_height="30dp"
android:background="#444eb9"
android:src="@drawable/back"/>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="80dp"
android:background="#444eb9"
android:editable="false"
android:enabled="false"
android:hint="size"
android:text="计一划"
android:textColor="#FFFFFF"
android:textIsSelectable="false"
android:textSize="20dp"
android:textStyle="bold"/>
</LinearLayout>
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="36dp"
android:layout_marginStart="36dp"
android:layout_marginTop="52dp"
android:text="早上"
android:textSize="20dp"
android:layout_below="@+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="33dp"
android:text="下午"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="20dp"
android:layout_below="@+id/MorningPlan"
android:layout_alignLeft="@+id/textView5"
android:layout_alignStart="@+id/textView5"/>
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="晚上"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="20dp"
android:layout_below="@+id/AfternoonPlan"
android:layout_alignLeft="@+id/textView7"
android:layout_alignStart="@+id/textView7"
android:layout_marginTop="36dp"/>
<EditText
android:id="@+id/MorningPlan"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignTop="@+id/textView5"
android:layout_marginLeft="30dp"
android:layout_marginRight="50dp"
android:layout_toRightOf="@+id/textView7"
android:background="@android:drawable/edit_text"
android:gravity="top|left"
android:hint="早上安排"
android:inputType="textMultiLine"
android:minLines="4"/>
<EditText
android:id="@+id/AfternoonPlan"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignLeft="@+id/MorningPlan"
android:layout_alignStart="@+id/MorningPlan"
android:layout_alignTop="@+id/textView7"
android:layout_marginRight="50dp"
android:background="@android:drawable/edit_text"
android:gravity="top|left"
android:hint="下午安排"
android:inputType="textMultiLine"
android:minLines="4"/>
<EditText
android:id="@+id/NightPlan"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_alignLeft="@+id/AfternoonPlan"
android:layout_alignStart="@+id/AfternoonPlan"
android:layout_alignTop="@+id/textView8"
android:layout_marginRight="50dp"
android:background="@android:drawable/edit_text"
android:gravity="top|left"
android:hint="晚上安排"
android:inputType="textMultiLine"
android:maxLines="4"/>
<Button
android:id="@+id/plan_sure"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_marginTop="30dp"
android:background="@drawable/buttonshape"
android:text="确定"
android:layout_below="@+id/NightPlan"
android:layout_alignLeft="@+id/textView8"
android:layout_alignStart="@+id/textView8"/>
<Button
android:id="@+id/plan_cancel"
android:layout_width="50dp"
android:layout_height="30dp"
android:background="@drawable/buttonshape"
android:text="取消"
android:layout_alignTop="@+id/plan_sure"
android:layout_alignRight="@+id/NightPlan"
android:layout_alignEnd="@+id/NightPlan"
android:layout_marginRight="10dp"/>
···
java代码
···
public class PlanActivity extends Activity implements View.OnClickListener {
//按钮
private Button PlanSure, PlanCancel;
//编辑框控件
private EditText MorningPlan, AfternoonPlan, NightPlan;
private ImageView PlanBack;
//数据库
private MySQLiteHelper mMysql;
private SQLiteDatabase mDataBase;
private ArrayList<String> Data = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.plan);
initView();
}
public void initView() {
PlanSure = (Button) findViewById(R.id.plan_sure);
PlanCancel = (Button) findViewById(R.id.plan_cancel);
MorningPlan = (EditText) findViewById(R.id.MorningPlan);
AfternoonPlan = (EditText) findViewById(R.id.AfternoonPlan);
NightPlan = (EditText) findViewById(R.id.NightPlan);
PlanBack = (ImageView)findViewById(R.id.imagePlanBack);
PlanSure.setOnClickListener(this);
PlanCancel.setOnClickListener(this);
PlanBack.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.plan_sure:
GetData();
WriteData();
break;
case R.id.plan_cancel:
this.finish();
break;
case R.id.imagePlanBack:
this.finish();
break;
}
}
public void GetData()
{
Data.clear();
Data.add(MorningPlan.getText().toString());
Data.add(AfternoonPlan.getText().toString());
Data.add(NightPlan.getText().toString());
}
public void WriteData()
{
mMysql = new MySQLiteHelper(this, "finance.db", null, 1);
mDataBase = mMysql.getReadableDatabase();
ContentValues cv=new ContentValues();
cv.put("Morningplan",Data.get(0));
cv.put("Afternoonplan",Data.get(1));
cv.put("Nightplan", Data.get(2));
mDataBase.insert("plan", "Nightplan", cv);
mDataBase.close();
mMysql.close();
//结束当前activity
this.finish();
}
}
···