最后冲刺 我的项目 广商小助手

 

package com.example.schoolall;

import java.util.ArrayList;
import java.util.HashMap;

import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

public class byActivity extends Activity{

private MediaPlayer kk;
private String[] names; //数据源
private ArrayList<HashMap<String,String>> listItem; //需求的数据结构
private ListView byListview; //列表对象
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.by);
kk=new MediaPlayer();
kk=MediaPlayer.create(byActivity.this, R.raw.mymusic);
// kk.start();

byListview = (ListView) findViewById(R.id.lv);/*定义一个动态数组*/
ArrayList<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>();/*在数组中存放数据*/
for(int i=0;i<10;i++)
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("ItemImage", R.drawable.empty_p);//加入图片
map.put("ItemTitle", "商品名称");
map.put("ItemText", "销量:"+i);
listItem.add(map);
}

SimpleAdapter mSimpleAdapter = new SimpleAdapter(this,listItem,//需要绑定的数据
R.layout.item,//每一行的布局
//动态数组中的数据源的键对应到定义布局的View中
new String[] {"ItemImage","ItemTitle", "ItemText"},
new int[] {R.id.ItemImage,R.id.ItemTitle,R.id.ItemText}
);

byListview.setAdapter(mSimpleAdapter);//为ListView绑定适配器
byListview.setOnItemClickListener(new OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
setTitle("你点击了第"+arg2+"行");//设置标题栏显示点击的行
}
});
}

}

package com.example.schoolall;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DatabaseHelper extends SQLiteOpenHelper
{
final static String DATABASENAME ="my_database.db";
final static int VERSION = 1;
final static String TABLENAME = "userInfo_detail";
final static String ID = "id";
final static String NAME = "name";
final static String SEX = "sex";
final static String AGE = "age";
final static String HOBBY = "hobby";
final static String PASSWORD = "password";

public DatabaseHelper(Context context)
{
super(context, DATABASENAME, null, VERSION);
// SQLiteOpenHelper 构造方法
}

@Override
public void onCreate(SQLiteDatabase db)
{
// 创建数据库,对数据库的操作
String sql2 = "CREATE TABLE " +
TABLENAME + "(" +
ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
NAME + " TEXT," +
PASSWORD + " TEXT," +
SEX + " TEXT," +
AGE + " TEXT," +
HOBBY + " TEXT);";
db.execSQL(sql2);
}

@Override
public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2)
{
// 每次成功打开数据库后首先被执行

}

}

package com.example.schoolall;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;


public class LoginActivity extends Activity{
private TextView appname_a;
private EditText xuehao_t,mima_t;
private ImageButton login_go_b;
private Button sign_up_b;
/*数据库用的对象*/
String name ;
String pass ;
String sex ;
String age ;
String hobby ;
SQLiteDatabase db;

@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.loginview);
sign_up_b=(Button) findViewById(R.id.zhuce);
appname_a=(TextView) findViewById(R.id.appname_t);
xuehao_t=(EditText) findViewById(R.id.name_in);
mima_t=(EditText) findViewById(R.id.pass_in);
appname_a.setText(Html.fromHtml( "<font color=#E61A6B>广</font>"+"<i><font color=#1111EE>商</font></i>"+"<font color=#BA55D3>小</font>"+"<font color=#FF1493>助</font>"+"<font color=#00FF00>手 </font> "));
login_go_b=(ImageButton) findViewById(R.id.roundBtn);

/*跳转到登录页面*/ login_go_b.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v)
{
DatabaseHelper helper = new DatabaseHelper(getBaseContext());
db = helper.getReadableDatabase();
name = xuehao_t.getText().toString();
pass = mima_t.getText().toString();
Log.e("",name+"||"+pass);
Cursor cursor = db.query(DatabaseHelper.TABLENAME,
new String[]{DatabaseHelper.PASSWORD},
DatabaseHelper.NAME + "=?",
new String[]{name}, null, null, null);
if (cursor.getCount() == 0 )
{
Toast.makeText(getBaseContext(), "该用户名不存在!!", Toast.LENGTH_LONG).show();
return;
}
cursor.moveToFirst();
String password = cursor.getString(0);
Log.e("true password",password);
if (password.equals(pass))
{
Intent i = new Intent(LoginActivity.this,MainActivity.class);
i.putExtra("name", name);
startActivity(i);
}
else
{
Toast.makeText(getBaseContext(), "密码错误!!", Toast.LENGTH_LONG).show();
}
}
});

/*跳转到注册页面*/ sign_up_b.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent signupIntent=new Intent();
signupIntent.setClass(LoginActivity.this,signupview.class);
startActivity(signupIntent);
}

});
}

}

package com.example.schoolall;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;

public class MainActivity extends Activity {

private ImageButton by_b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
by_b=(ImageButton) findViewById(R.id.imageButton1);
by_b.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent byIntent=new Intent();
byIntent.setClass(MainActivity.this, downloadpicture.class);
startActivity(byIntent);
}

});
}


@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;
}

}

package com.example.schoolall;


import android.app.Activity;
import android.content.ContentValues;
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.Button;
import android.widget.EditText;
import android.widget.Toast;

public class signupview extends Activity{
private Button commit_up;

//数据库对象
String name ;
String pass ;
String sex ;
String age ;
String hobby ;
SQLiteDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_up);
final EditText et1 = (EditText) findViewById(R.id.name_in);
final EditText et2 = (EditText) findViewById(R.id.pass_in);
final EditText et3 = (EditText) findViewById(R.id.sex_in);
final EditText et4 = (EditText) findViewById(R.id.age_in);
final EditText et5 = (EditText) findViewById(R.id.hobby_in);
Button okBtn = (Button) findViewById(R.id.okBtn);
okBtn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
name = et1.getText().toString();
pass = et2.getText().toString();
sex = et3.getText().toString();
age = et4.getText().toString();
hobby= et5.getText().toString();

DatabaseHelper helper = new DatabaseHelper(getBaseContext());
db = helper.getWritableDatabase();
//在数据库中查找一条数据 表名 数据库列名称数组 查询条件 分组列 分组条件 排序列。。。
Cursor cursor = db.query(DatabaseHelper.TABLENAME,
new String[]{DatabaseHelper.NAME},
DatabaseHelper.NAME + "=?",
new String[]{name}, null, null, null);
if (cursor.getCount()>0)
{
Toast.makeText(getBaseContext(), "该用户已存在!!", Toast.LENGTH_LONG).show();
return;
}
ContentValues values = new ContentValues();//应用间共享数据的唯一方式
values.put(DatabaseHelper.NAME, name);
values.put(DatabaseHelper.PASSWORD, pass);
values.put(DatabaseHelper.SEX, sex);
values.put(DatabaseHelper.AGE, age);
values.put(DatabaseHelper.HOBBY, hobby);
db.insert(DatabaseHelper.TABLENAME, null, values);

Intent i = new Intent(signupview.this,MainActivity.class);
i.putExtra("name", name);
startActivity(i);
}
});
}
}

项目还在做

 

posted @ 2015-12-19 17:18  31-范铭祥  阅读(135)  评论(0编辑  收藏  举报