android 开发积累

来源:互联网 发布:绣花软件免费下载 编辑:程序博客网 时间:2024/06/07 02:43

1.  android activity 不会展示 title appname之类的方法

android:theme="@android:style/Theme.NoTitleBar"

2. openOrCreateDatabase

Context.openOrCreateDatabase 与 SQLiteDatabase.openOrCreateDatabase本质上完成的功能都一样,Context.openOrCreateDatabase最终是需要调用 SQLiteDatabase.openOrCreateDatabase来完成数据库的创建的。

也就是说, SQLiteDatabase类是android上对sqlite的最底层的封装,几乎所有的对数据库的操作最终都通过这个类来实现。

而Context里面提供的方法,是用于上下文的时候创建数据库,例如你在某个逻辑里面创建的数据库只是在特定的context里面,对于数据库的权限,交由context来管理,而这个逻辑可能是会提供给不止一个context


至于SQLiteDatabase和SQLiteOpenHelper就更好理解了,后者只是一个抽象类,用来告诉你怎样使用SQLiteDatabase类而已,你完全可以自己基于SQLiteDatabase写一个自己的helper.


3. 界面返回按钮的事件      

goback = (ImageView)findViewById(R.id.mysc_goback);


        //返回按钮的函数
        goback.setOnClickListener(new OnClickListener(){
            @Override
            public void onClick(View v) {
                MyScActivity.this.finish();
            }

        });

4. 得到网络文件大小的方法

                            HttpManager hm = new HttpManager(Const.IR_URL+ir_name);        
                            long newsize = hm.getContentLength();//获取新文件大小

/** * 获取返回内容长度 * @return */public long getContentLength(){long len = -1;if(httpclient!=null && httpPost!=null && !httpPost.isAborted()){//设置httpPost请求参数及编码try {List<NameValuePair> params = new ArrayList<NameValuePair>();httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));} catch (UnsupportedEncodingException e1) {Log.e(Const.TAG, "getContentLength 输入参数编码有问题:UnsupportedEncodingException");return len;}//第二步,使用execute方法发送HTTP POST请求,并返回HttpResponse对象try {httpResponse =httpclient.execute(httpPost);} catch (ClientProtocolException e) {Log.e(Const.TAG, "getContentLength 服务器无应答:ClientProtocolException");} catch (IOException e) {Log.e(Const.TAG, "getContentLength 服务器无应答:IOException");} catch (Exception e) { Log.e(Const.TAG, "getContentLength 服务器无应答:OtherException");         }if(httpResponse!=null && (httpResponse.getStatusLine().getStatusCode() == 200)){//第三步,使用getEntity方法活得返回结果    try {    HttpEntity httpEntity = httpResponse.getEntity();    len = httpEntity.getContentLength();} catch (Exception e) {Log.e(Const.TAG, "getContentLength 返回结果异常:OtherException"); }}httpPost.abort();httpclient.getConnectionManager().closeExpiredConnections();}Log.d(Const.TAG, "HttpManager.getContentLength|len="+len);return len;}


原创粉丝点击