弄了 好半天
你要先配置一下环境 path 找到sdk
忘记装哪里 你就看这儿 tools 下面的 sdk 管理器
看完之后找到位置
找到之后 配置到电脑path 里
我之后运行还是不行 adb root 就是不行 差了一下午 感觉是版本太高了 重弄了 一个模拟器 是安卓6.0版本的 就能root了 希望大佬给谁会能给俺说说
授权之后 又一个问题 我竟然找不到 ddms 没办法 就是 一顿找 找到view 里面 的terminal输入 monitor 结果端口占用 但是好歹能用 问问老师咋回事儿
贴一下今天的布局 是 登录 的账号 和密码
看看 activity 怎么使用的sharedpreference
public class SharedPreferences1Activity extends AppCompatActivity { EditText txtName,txtPassword; Button btnOk; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_shared_preferences1); txtName=(EditText)findViewById(R.id.txtName); txtPassword=(EditText)findViewById(R.id.txtPassword); btnOk=(Button)findViewById(R.id.btnOk); SharedPreferences sharedPreferences=getSharedPreferences("user", Context.MODE_PRIVATE); //user是文件名,即user.xml,保存在/data/data/weili.org.myapplication/shared_prefs/user.xml String userName=sharedPreferences.getString("userName",""); String userPassword=sharedPreferences.getString("userPassword",""); if(!userName.equals("")) txtName.setText(userName); if(!userPassword.equals("")) txtPassword.setText(userPassword); btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { SharedPreferences sharedPreferences=getSharedPreferences("user", Context.MODE_PRIVATE); SharedPreferences.Editor editor=sharedPreferences.edit(); editor.putString("userName",txtName.getText().toString()); editor.putString("userPassword",txtPassword.getText().toString()); editor.commit(); } }); }
刚才是sharedpreferences写入文件 的 程序 现在是file的
效果:
他放下这个默认的file的下面
fileactivity
public class FileActivity extends AppCompatActivity { EditText txtFileName,txtFileContent1,txtFileContent2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_file); txtFileName=(EditText)findViewById(R.id.txtFileName); txtFileContent1=(EditText)findViewById(R.id.txtFileContent1); txtFileContent2=(EditText)findViewById(R.id.txtFileContent2); } public void btnWriteClick(View v){ String fileName=txtFileName.getText().toString().trim(); if(fileName.equals("")) return; FileOutputStream fout=null; try { fout=openFileOutput(fileName, Context.MODE_APPEND);//写入文件名字 String fileContent=txtFileContent1.getText().toString();//写入文件文字 fout.write(fileContent.getBytes()); } catch (FileNotFoundException e) { System.out.println(fileName+" 不存在"); } catch (IOException e) { System.out.println("写入数据到文件 "+fileName+" 失败:"+e.getMessage()); } } public void btnReadClick(View v){ String fileName=txtFileName.getText().toString().trim(); byte[] buffer=new byte[1024]; int count=0; StringBuffer sb=new StringBuffer(); if(fileName.equals("")) return; FileInputStream fin=null; try { fin=this.openFileInput(fileName); String fileContent=txtFileContent1.getText().toString(); while((count=fin.read(buffer))!=-1){ sb.append(new String(buffer,0,count)); } txtFileContent2.setText(sb.toString()); } catch (FileNotFoundException e) { System.out.println(fileName+" 不存在"); } catch (IOException e) { System.out.println("从"+"fileName+" +"读入数据失败:"+e.getMessage()); } } }
sql 建一个 老师的数据库来增删改
效果图如下
要先写 sqliteopenhelper类
创建数据库
public class MyDatabaseHelper extends SQLiteOpenHelper { public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) { super(context, name, factory, version); } public MyDatabaseHelper(Context context, String name, int version) { super(context, name, null, version); } public MyDatabaseHelper(Context context,String name){ super(context,name,null,1); } public MyDatabaseHelper(Context context){ super(context,"teacherDB",null,1); } //第一次被 @Override public void onCreate(SQLiteDatabase db) { String sqlCreateTableTeacher="create table teacher(teacherid text primary key,teachername text,sex text,money integer)"; db.execSQL(sqlCreateTableTeacher); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } } 然后写控制数据库的
public class TeacherActivity extends AppCompatActivity { EditText teacherId,teacherName,teacherSex,teacherMoney; MyDatabaseHelper dbHelper; TextView txtResult; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_teacher); teacherId=(EditText) findViewById(R.id.teacherId); teacherName=(EditText) findViewById(R.id.name); teacherSex=(EditText) findViewById(R.id.sex); teacherMoney=(EditText) findViewById(R.id.money); txtResult=(TextView)findViewById(R.id.txtResult) ; dbHelper=new MyDatabaseHelper(TeacherActivity.this,"teacherDB",1); } public void btnAddClick(View view){ String id=teacherId.getText().toString().trim(); String name=teacherName.getText().toString().trim(); String sex=teacherSex.getText().toString().trim(); String money=teacherMoney.getText().toString().trim(); String insertSql="insert into teacher(teacherid,teachername,sex,money) values(?,?,?,?)"; SQLiteDatabase db=dbHelper.getReadableDatabase(); db.execSQL(insertSql,new String[]{id,name,sex,money}); btnQueryClick(view); //System.out.println("插入成功"); } public void btnUpdateClick(View view){ String id=teacherId.getText().toString().trim(); String name=teacherName.getText().toString().trim(); String sex=teacherSex.getText().toString().trim(); String money=teacherMoney.getText().toString().trim(); String updateSql="update teacher set teachername=?,sex=?,money=? where teacherid=?"; SQLiteDatabase db=dbHelper.getReadableDatabase(); db.execSQL(updateSql,new Object[]{name,sex,money,id}); btnQueryClick(view); } public void btnDeleteClick(View view){ String id=teacherId.getText().toString().trim(); if(id.length()==0) return; SQLiteDatabase db=dbHelper.getReadableDatabase(); String sqlDelete="delete from teacher where teacherid=?"; db.execSQL(sqlDelete,new String[]{id}); btnQueryClick(view); } public void btnQueryClick(View view){ String sqlSelect="select * from teacher"; SQLiteDatabase db=dbHelper.getReadableDatabase(); Cursor cursor=db.rawQuery(sqlSelect,null);//Cursor相当于jdbc的ResultSet txtResult.setText(""); while(cursor.moveToNext()){ String id=cursor.getString(0); String name=cursor.getString(1); String sex=cursor.getString(2); String money=cursor.getString(3); txtResult.append("\t\t\t\t\t\t"+id+"\t\t\t\t\t"+name+"\t\t\t\t"+sex+"\t\t\t\t"+money+"\n"); } } }