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);
}
});
}
}
專案還在做