android课程设计问题简介

大道之行,天下为公。这篇文章主要讲述android课程设计问题简介相关的知识,希望能为你提供帮助。
【android课程设计问题简介】以下是从零开始一步一步幸苦摸索得来的一些经验和方法,虽然看不懂但还是坚持看坚持改,所以贵在坚持
1,第一个界面写入sp始终虚拟即出现错误,后来再lab3上面修改 lab3原来是登陆界面并把用户和密码写入sp中。 只是把写sp改为注册,并消除界面信息

loginBt.setOnClickListener(new OnClickListener(){ public void onClick(View v){ if(qqNo.getText().toString().equals("")||qqPsw.getText().toString().equals("")){ Toast toast = Toast.makeText(getApplicationContext(), "请输入学号,姓名", Toast.LENGTH_SHORT); toast.show(); } else{ //通过Editor对象存储key-value键值对数据 edit.putString("qqno",qqNo.getText().toString()); edit.putString("qqpwd",qqPsw.getText().toString()); //edit.putString("班级",banji.getText().toString()); //通过commit()方法提交数据 edit.commit(); Toast toast = Toast.makeText(getApplicationContext(), "注册成功", Toast.LENGTH_SHORT); toast.show(); qqNo.setText(""); qqPsw.setText(""); } } });

登陆按钮。比较登陆的用户密码与sp做比较,然后跳转.跳转是一个麻烦事
Rdsp.setOnClickListener(new OnClickListener(){ public void onClick(View v){ /*if(null!=sp.getString("qqno","")) { qqNo.setText(sp.getString("qqno","")); } if(null!=sp.getString("qqpwd","")) { qqPsw.setText(sp.getString("qqpwd","")); }*/if(qqNo.getText().toString().equals(sp.getString("qqno",""))& qqPsw.getText().toString().equals(sp.getString("qqpwd",""))) { Toast toast = Toast.makeText(getApplicationContext(), "登陆成功", Toast.LENGTH_SHORT); toast.show(); Intent intent = new Intent (MainActivity.this,addressbook.class); startActivity(intent); MainActivity.this.finish(); } else { Toast toast = Toast.makeText(getApplicationContext(), "登陆失败", Toast.LENGTH_SHORT); toast.show(); } } });

 
2,界面跳转问题 新建.java文件,选择父类Oncreate方法
Intent intent = new Intent (MainActivity.this,addressbook.class); startActivity(intent); MainActivity.this.finish();

  跳转后的界面
protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.addressbook); }

在androidManifest.xml文件中注册活动
< application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" > < activity android:name="com.dxxy.lab3.MainActivity" android:label="@string/app_name" > < intent-filter> < action android:name="android.intent.action.MAIN" /> < category android:name="android.intent.category.LAUNCHER" /> < /intent-filter> < /activity> < activity android:name=".addressbook" android:label="@string/app_name" > < /activity>

3,添加朋友,加入朋友表,并根据weichat判断是否重复添加(借鉴 第十四章 EasyNotepad) 建表  但自己不懂这种方法的详细操作步骤只会判断是否添加重复,不会查找里面数据(在后面提到用另外的一种建表方法解决)
public class SqlHelp extends SQLiteOpenHelper { static int Ver = 1; // 数据库的版本号 public static String TableUser = "User"; // 用户表 public static String TableNote = "Note"; // 日记表 public static String DBName = "Np.db"; // 数据库名字 // 多态构造函数 public SqlHelp(Context context, String name, CursorFactory factory, int version) { super(context, name, factory, version); // TODO 自动生成的构造函数存根 } // 多态构造函数 public SqlHelp(Context context, String name, int version) { this(context, name, null, version); // TODO 自动生成的构造函数存根 } // 多态构造函数 public SqlHelp(Context context, String name) { this(context, name, Ver); // TODO 自动生成的构造函数存根 } // 创建数据库 @Override public void onCreate(SQLiteDatabase db) { // TODO 自动生成的方法存根 String sql = "Create Table " + TableUser + "(password long primary key ,username varchar(100))"; db.execSQL(sql); sql = "Create Table " + TableNote + "(id integer primary key autoincrement,title varchar(100),plain varchar(100),date varchar(100))"; db.execSQL(sql); } // 更新数据库 @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO 自动生成的方法存根 } }

  判断
public class friendadd extends Activity {Button regButton; EditText usernameEditText; EditText passwordEditText; // 2 数据库操作变量 SQLiteDatabase db; SqlHelp dbhelp; //@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.friendadd); usernameEditText = (EditText) findViewById(R.id.friend_user); passwordEditText = (EditText) findViewById(R.id.friend_weichat); regButton = (Button) findViewById(R.id.tianjia); // 3 用户注册功能 regButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO 自动生成的方法存根 dbhelp = new SqlHelp(friendadd.this, SqlHelp.DBName); db = dbhelp.getReadableDatabase(); Cursor cursor = db.query(SqlHelp.TableUser, null, "password=?", new String[] { passwordEditText.getText().toString() .trim() }, null, null, null); int a = cursor.getCount(); db.close(); cursor.close(); if (usernameEditText.getText().toString().trim().equals("") || passwordEditText.getText().toString().trim() .equals("")) { Toast.makeText(friendadd.this, "用户名或密码不能为空!", Toast.LENGTH_LONG).show(); } else if (a == 0) { db = dbhelp.getWritableDatabase(); ContentValues values = new ContentValues(); values.put("username", usernameEditText.getText() .toString().trim()); values.put("password", passwordEditText.getText() .toString().trim()); db.insert(SqlHelp.TableUser, null, values); Toast.makeText(friendadd.this, "添加朋友成功!", Toast.LENGTH_LONG).show(); } else { Toast.makeText(friendadd.this, "微信号重复!", Toast.LENGTH_LONG).show(); } } }); }

 
4,今天解决的问题,界面跳转问题·,并带上数据
Intent intent = new Intent(); intent.putExtra("name",usernameEditText.getText().toString() ); intent.putExtra("weichat",passwordEditText.getText().toString()); intent.setClass(friendadd.this,addressbook.class); friendadd.this.startActivity(intent);

跳转后的页面取出数据
Intent intent = getIntent(); String tnNumber = intent.getStringExtra("name"); String payMode = intent.getStringExtra("weichat"); ll = (ListView) findViewById(R.id.listView1); ArrayList< HashMap< String,Object> > users = new ArrayList< HashMap< String, Object> > (); HashMap< String, Object> user = new HashMap< String, Object> (); user.put("pic",tnNumber); user.put("small", payMode); users.add(user); SimpleAdapter adapter = new SimpleAdapter(this, users, R.layout.detail, new String[]{"pic","small",}, new int[]{R.id.text1,R.id.text2}); ll.setAdapter(adapter);

  5,单击一个listview,跳转到另外一个activity
private ListView ll; ll = (ListView) findViewById(R.id.listView1) ll.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView< ?> parent, View view, int position, long id) { //position 点击的Item位置,从0开始算 Intent intent=new Intent(addressbook.this,friendadd.class); intent.putExtra("xx",""); //传递给下一个Activity的值 startActivity(intent); //启动Activity } });

 
6,qq的聊天功能 三大程序 ChatActivity.java ,ChatMsgViewAdapter.java ,ChatMsgEntity.java
public class ChatActivity extends Activity implements OnClickListener{private Button mBtnSend; private Button mBtnBack; private EditText mEditTextContent; private ListView mListView; private ChatMsgViewAdapter mAdapter; private List< ChatMsgEntity> mDataArrays = new ArrayList< ChatMsgEntity> (); privateString value; protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.chat_friend); //启动activity时不自动弹出软键盘 getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN); Intent intent = getIntent(); value =https://www.songbingjia.com/android/intent.getStringExtra("name"); initView(); initData(); } public void initView() { mListView = (ListView) findViewById(R.id.listview); mBtnSend = (Button) findViewById(R.id.btn_send); mBtnSend.setOnClickListener(this); mBtnBack = (Button) findViewById(R.id.btn_back); mBtnBack.setOnClickListener(this); mBtnBack = (Button) findViewById(R.id.btn_qury); mBtnBack.setOnClickListener(this); mEditTextContent = (EditText) findViewById(R.id.et_sendmessage); } public void initData() {ChatMsgEntity entity = new ChatMsgEntity(); entity.setDate(getDate()); entity.setName(value); entity.setMsgType(true); mDataArrays.add(entity); mAdapter = new ChatMsgViewAdapter(this, mDataArrays); mListView.setAdapter(mAdapter); }@Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()) { case R.id.btn_send: send(); break; case R.id.btn_back: Intent intent1 = new Intent (ChatActivity.this,addressbook.class); startActivity(intent1); break; case R.id.btn_qury: Intent intent2 = new Intent (ChatActivity.this,qury.class); startActivity(intent2); break; }}private void send() { String contString = mEditTextContent.getText().toString(); if (contString.length() > 0) { //发送方 ChatMsgEntity entity = new ChatMsgEntity(); entity.setDate(getDate()); entity.setName("李刚"); entity.setMsgType(false); entity.setText(contString); mDataArrays.add(entity); mAdapter.notifyDataSetChanged(); mEditTextContent.setText(""); mListView.setSelection(mListView.getCount() - 1); //接收方 ChatMsgEntity entity2 = new ChatMsgEntity(); entity2.setName(value); entity2.setMsgType(true); entity2.setText(value+"朋友收到的信息是:"+contString); mDataArrays.add(entity2); mAdapter.notifyDataSetChanged(); mEditTextContent.setText(""); mListView.setSelection(mListView.getCount() - 1); } }private String getDate() { Calendar c = Calendar.getInstance(); String year = String.valueOf(c.get(Calendar.YEAR)); String month = String.valueOf(c.get(Calendar.MONTH)); String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH) + 1); String hour = String.valueOf(c.get(Calendar.HOUR_OF_DAY)); String mins = String.valueOf(c.get(Calendar.MINUTE)); StringBuffer sbBuffer = new StringBuffer(); sbBuffer.append(year + "-" + month + "-" + day + " " + hour + ":" + mins); return sbBuffer.toString(); }public void head_xiaohei(View v) {//标题栏 返回按钮 //Intent intent = new Intent (ChatActivity.this,InfoXiaohei.class); //startActivity(intent); }

 

    推荐阅读