1.遇到的问题。
1.error://Unfortunately,MyQQ has stopped.在模拟器运行的时候出现此错
解决方法:
当前页面调用 android.support.v7.app.ActionBarActivity,继承ActionBarActivity
//将其删除,调用import android.app.Activity;继承Activity
有的时候获取是其他方面的问题,如:AndroidManifest.xml配置问题。具体看logCat报的提示。
2.error:Android library projects can not be launched
解决方法:
选择工程Properties ,将isLibrary 勾选去掉。不要appcompat_v7
3.error:xml中LinearLayout报错
解决方法:
添加android:orientation="vertical"
----------
android:layout_gravity ( 是本元素相对于父元素的重力方向 )
android:gravity (是本元素所有子元素的重力方向)
android:orientation (线性布局以列或行来显示内部子元素)
android:layout_weight (线性布局内子元素对未占用空间【水平或垂直】分配权重值,其值越小,权重越大。
前提是子元素 设置了 android:layout_width = "fill_parent" 属性(水平方向)
或 android:layout_height = "fill_parent" 属性(垂直方向)
如果某个子元素的 android:layout_width = "wrap_content"
或 android:layout_height =" wrap_content” ,
则 android:layout_weight 的设置值 对该方向上空间的分配刚好相反。
来源:http://li-bonan.blog.163.com/blog/static/135564770201172441634145/
2.记录相关知识点
1.对于声明对象,字段,快速生成,可以ctr +2 选择。
2.button 单击事件
btnlogin.setOnClickListener(this);//(implements)页面实现借口OnClickListener,------public class MainActivity extends Activity implements OnClickListener {}
3.Map<String, String> 类似于c#中字典。
Map<String, String> map=new HashMap<String, String>();
map.put("number", stringArryStrings[0]);
map.put("password", stringArryStrings[1]);
4.保存文件到手机内存中-----FileOutputStream
String pathString="data/data/com.example.myqq/info.txt";
FileOutputStream fos=new FileOutputStream(pathString);
String dataString=name+"##"+password;
fos.write(dataString.getBytes());
fos.flush();
fos.close();
5.获取手机内存中的数据----FileInputStream,BufferedReader,
String pathString="data/data/com.example.myqq/info.txt";
FileInputStream fis=new FileInputStream(pathString);
//字符流对象
BufferedReader reader=new BufferedReader(new InputStreamReader(fis));
String textString=reader.readLine();
代码如下:
package com.example.myqq.Util; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import android.R.string; import android.text.TextUtils; public class Util { //保存数据到 public boolean saveUserInfo(String name,String password) { try { String pathString="data/data/com.example.myqq/info.txt"; FileOutputStream fos=new FileOutputStream(pathString); String dataString=name+"##"+password; fos.write(dataString.getBytes()); fos.flush(); fos.close(); } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return true; } public Map<String, String> getUserInfo() { try { String pathString="data/data/com.example.myqq/info.txt"; FileInputStream fis=new FileInputStream(pathString); //字符流对象 BufferedReader reader=new BufferedReader(new InputStreamReader(fis)); String textString=reader.readLine(); if(!TextUtils.isEmpty(textString)) { String[] stringArryStrings= textString.split("##"); Map<String, String> map=new HashMap<String, String>(); map.put("number", stringArryStrings[0]); map.put("password", stringArryStrings[1]); return map; } return null; } catch (Exception e) { // TODO: handle exception e.printStackTrace(); } return null; } }
<LinearLayout 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:orientation="vertical" tools:context=".MainActivity" > <EditText android:id="@+id/et_number" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="请输入QQ号" /> <EditText android:id="@+id/et_password" android:layout_width="fill_parent" android:layout_height="wrap_content" android:hint="请输入密码" android:inputType="textPassword" /> <CheckBox android:id="@+id/cb_remerber_pwd" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="记住密码" /> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="登录" /> </LinearLayout>