Skip to content

Commit

Permalink
Merge pull request #829 from SimpleCodeCX/master
Browse files Browse the repository at this point in the history
实验二,更新activity文件 #88
  • Loading branch information
zengsn committed May 25, 2016
2 parents d092f49 + 232641c commit dd43319
Show file tree
Hide file tree
Showing 15 changed files with 403 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,15 +1,65 @@
package com.example.myapp;
package com.example.passwordbox;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Com1314080901208 extends Activity {

private MyDatabaseHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_com1314080901208);
dbHelper=new MyDatabaseHelper(this, "PasswordBox.db", null, 2);
Button TiJiaoBtn=(Button)findViewById(R.id.TiJiaoBtn);
TiJiaoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub

EditText userNameText=(EditText)findViewById(R.id.userName);
EditText paddwordText=(EditText)findViewById(R.id.password);
SQLiteDatabase db=dbHelper.getWritableDatabase();
// 查询Login表中所有的数据
Cursor cursor=db.rawQuery("select * from Login where userName='"+userNameText.getText().toString()+"'", null);
if(cursor.getCount()==0)
{
Toast.makeText(Com1314080901208.this,"用户名不存在",Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Com1314080901208.this,"登录成功",Toast.LENGTH_LONG).show();
Intent intent=new Intent(Com1314080901208.this,AcountListView.class);//显示Intent
startActivity(intent);
}

//Toast.makeText(Com1314080901208.this,cursor.getCount(),Toast.LENGTH_LONG).show();
// Intent intent = new Intent("com.example.passwordbox.ACTION_START");//隐式Intent
// intent.addCategory("android.intent.category.MY_CATEGORY");//这里指定了Category为MY_CATEGORY,如果没有指定这个时默认为default
// //Intent intent=new Intent(Com1314080901208.this,activity2.class);//显示Intent
// startActivity(intent);
}
});

//点击注册跳转到注册页面
Button RegisterBtn=(Button)findViewById(R.id.RegisterBtn);
RegisterBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(Com1314080901208.this,Register.class);
startActivity(intent);
}
});

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<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:background="@drawable/login_bg"
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=".Com1314080901208" >


<RelativeLayout
android:id="@+id/rl1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<EditText
android:id="@+id/userName"
android:layout_width="fill_parent"
android:layout_height="50px"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:background="#7FFFD4"
android:hint="请输入用户名" />
</RelativeLayout>

<RelativeLayout
android:id="@+id/rl2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl1" >

<EditText
android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="50px"
android:layout_centerVertical="true"
android:layout_margin="20dp"
android:background="#7FFFD4"
android:hint="请输入密码"
android:textColor="#FFF" />
</RelativeLayout>



<RelativeLayout
android:id="@+id/rl3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl2" >

<Button
android:id="@+id/TiJiaoBtn"
android:layout_width="fill_parent"
android:layout_height="60px"
android:layout_centerVertical="true"
android:layout_margin="30dp"
android:text="登录"
android:background="#458B74"
android:textColor="#FFF" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/rl4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/rl3" >

<Button
android:id="@+id/RegisterBtn"
android:layout_width="wrap_content"
android:layout_height="60px"
android:layout_centerVertical="true"

android:layout_marginTop="200dp"
android:text="注册"
android:background="#458B74"
android:textColor="#FFF" />
</RelativeLayout>

</RelativeLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.example.passwordbox;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class AcountListView extends Activity{
private List<AcountData> acountList=new ArrayList<AcountData>();
private MyDatabaseHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.acount_listview);
initAcount();
AcountAdapter adapter=new AcountAdapter(AcountListView.this,R.layout.acount_item, acountList);
ListView listView=(ListView)findViewById(R.id.list_view_acount);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,int position, long id)
{
AcountData acountData = acountList.get(position);
Intent intent=new Intent(AcountListView.this,AcountDetails.class);//显示Intent
intent.putExtra("acountId", String.valueOf(acountData.getAcountId()));
startActivity(intent);
}
});
Button addAcountBtn=(Button)findViewById(R.id.addAcountBtn);
addAcountBtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent=new Intent(AcountListView.this,AddAcount.class);//显示Intent
startActivity(intent);
}
});
}
private void initAcount()
{
dbHelper=new MyDatabaseHelper(this, "PasswordBox.db", null, 2);
SQLiteDatabase db=dbHelper.getWritableDatabase();
// 查询Acount表中所有的数据
Cursor cursor=db.rawQuery("select * from Acount", null);
if(cursor.moveToFirst())
{
do{
int id=cursor.getInt(cursor.getColumnIndex("id"));
String acountLabel=cursor.getString(cursor.getColumnIndex("acountLabel"));
AcountData acountData=new AcountData(id,acountLabel);
acountList.add(acountData);
}
while(cursor.moveToNext());
}
cursor.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.example.passwordbox;

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddAcount extends Activity{
private MyDatabaseHelper dbHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.add_acount);
dbHelper=new MyDatabaseHelper(this, "PasswordBox.db", null, 2);
Button addCountBtn=(Button)findViewById(R.id.addCount);
addCountBtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
EditText userName = (EditText) findViewById(R.id.userName);
EditText password = (EditText) findViewById(R.id.password);
EditText notes = (EditText) findViewById(R.id.notes);
EditText acountLabel = (EditText) findViewById(R.id.acountLabel);
SQLiteDatabase db = dbHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("acountLabel", acountLabel.getText().toString());
values.put("userName", password.getText().toString());
values.put("password", userName.getText().toString());
values.put("notes", notes.getText().toString());
db.insert("Acount", null, values);
Toast.makeText(AddAcount.this,"Ìí¼ÓÕ˺ųɹ¦",Toast.LENGTH_LONG).show();
Intent intent=new Intent(AddAcount.this,AcountListView.class);//ÏÔʾIntent
startActivity(intent);
}
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.passwordbox"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.passwordbox.Com1314080901208"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- 这里是activity2 -->
<activity
android:name="com.example.passwordbox.activity2"
android:label="activity2">
<intent-filter>
<!-- 在<action> 标签中我们指明了当前活动可以响应com.example.passwordbox.ACTION_START 这个action -->
<action android:name="com.example.passwordbox.ACTION_START" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.MY_CATEGORY" />
</intent-filter>
</activity>
<!-- 这里是 register-->
<activity
android:name="com.example.passwordbox.Register"
android:label="Register">
</activity>
<!-- 这里是 AddAcount-->
<activity
android:name="com.example.passwordbox.AddAcount"
android:label="AddAcount">
</activity>

<!-- 这里是 AcountListView-->
<activity
android:name="com.example.passwordbox.AcountListView"
android:label="AcountListView">
</activity>
<!-- 这里是 AcountDetails-->
<activity
android:name="com.example.passwordbox.AcountDetails"
android:label="AcountDetails">
</activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content">

<Button
android:id="@+id/addAcountBtn"
android:layout_width="fill_parent"
android:layout_height="60px"
android:layout_centerVertical="true"
android:layout_margin="30dp"
android:text="添加账号"
android:background="#458B74"
android:textColor="#FFF" />
</RelativeLayout>
<ListView
android:id="@+id/list_view_acount"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<EditText android:id="@+id/acountLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="标签如:淘宝账号" />
<EditText android:id="@+id/userName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入用户名" />
<EditText android:id="@+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="请输入密码" />
<EditText android:id="@+id/notes"
android:layout_width="fill_parent"
android:layout_height="150px"
android:hint="请输入账号描述" />
<Button android:id="@+id/addCount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="添加账号"/>
</LinearLayout>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit dd43319

Please sign in to comment.