跳至主要内容

博文

目前显示的是 五月, 2013的博文

Android Sqlite INSERT OR REPLCACE index

Android Sqlite INSERT OR REPLCACE 主键非 _id 前题: 今天遇到一个问题,我们本地存了多条评论来自不同的表。 原本的设计是拿服务器上的id直接当成本地的 _id 字段,但是一样是来自不同的表,这样就会出现id有可能重复的问题,所以当我想本地和服务器同步数据时 使用 INSERT OR UPDATE 就会出现问题。 因为出现了上述问题,所以我就开始想之前的在的数据是怎么实现的。 于是 查看之前的代码。 "insert or replace into " + TABLE_NAME_CATEGORY_ARTICLES + "(" + FIELDS_CATEGORY_ARTICLES + ") values ” + "(?, ?, ?, ?, ?, ?, ?, ?)"; 从这段代码里没有发现任何用于判断是决定更新还是新建,所以再向前…… "CREATE TABLE IF NOT EXISTS " + TABLE_NAME_CATEGORY_ARTICLES + "(_id INTEGER PRIMARY KEY," + "category TEXT, " + "title TEXT, " + "summary TEXT, " + "content TEXT, " + "created_at TIMESTAMP, " + "readFlg BOOLEAN, " + "thumbnail TEXT)"; 我们找到了建表语句,在这里只发现了,primary key, 再没有其它的东西了,所以我推测它应该是通过 _id 这个primary key来确定是否存在这条记录来决定 是更新还是新建。 这了确定我的推测是正确的,我google了一下,果然…… 回到我之前的问题,我们现在不能使用 _id 这个主键来确定是更新还是插入了。于是我就查一下文档,发现 sqlite 可以有另一种方式来约

How to debug Android without usb?

first you must make sure you have a wireless device and your android devices can connect your computer with ip address. If you have connected with usb ,you can go adb shell run this: adb tcpip 5555 Then you can connect with you network, like this : adb connect ip:5555    this is should be you phone ip. If you are want one key start,  there have a app named  wireless  you can download in play, so easy and good luck.

how to make your click event and handler easier to read in Android Activities

How to make your click event and handler easy to read. If you have one button event in your activity, you can add listener like this. final String test = "test"; findViewById(R.id.button).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), test, Toast.LENGTH_SHORT).show(); } }); But this is rarely.  Also you wrote it everywhere like this.  findViewById(R.id.button1).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), test, Toast.LENGTH_SHORT).show(); } }); findViewById(R.id.button2).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), test, Toast.LENGTH_SHORT).show(); } }); findViewById(R.id.button3).setOnClickListener(new OnClickListener() { @Override publ