助考100%,祝你取得好成绩.

来源:互联网 发布:windows车载系统 编辑:程序博客网 时间:2024/05/19 05:38
1.GreenDao
1.  要在新建的module模块对应的build.gradle里面配置依赖包以及生成类的位置
dependencies {//依赖包    classpath 'com.android.tools.build:gradle:2.2.3'    classpath 'org.greenrobot:greendao-gradle-plugin:3.2.0'    // NOTE: Do not place your application dependencies here; they belong    // in the individual module build.gradle files}

2.

dependencies {    compile fileTree(dir: 'libs', include: ['*.jar'])    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {        exclude group: 'com.android.support', module: 'support-annotations'    })    compile 'com.android.support:appcompat-v7:25.0.1'    testCompile 'junit:junit:4.12'    compile 'org.greenrobot:greendao:3.2.0'}

在顶部声明部位

apply plugin: 'com.android.application'apply plugin: 'org.greenrobot.greendao'

 在android{}添加

android {    compileSdkVersion 25    buildToolsVersion "23.0.3"        greendao{        schemaVersion 1        daoPackage 'com.jiyun.com.day07_greendao'        targetGenDir 'src/main/java'    }    }

 

 

@Entity(nameInDb = "message")public class Message {    @Property(nameInDb = "id")    @Id(autoincrement = true)    private Long id;        @Property(nameInDb = "name")    private String name;    @Property(nameInDb = "content")    private String content;    @Property(nameInDb = "image")    private String img1;

实现数据库修改:

1.Bean类实例化,Intent传对象,

Intent intent=new Intent(SecondActivity.this,SanActivity.class);intent.putExtra("bean",list.get(i));startActivityForResult(intent,200);

2.接收,修改

Intent intent = getIntent();bean = intent.getParcelableExtra("bean");
bean.setName(editTextString);bean.setShop(editText2String);bean.setImage(R.mipmap.ic_launcher);DaoMangger.getIntance(SanActivity.this).getDap().update(bean);
3.回传
Intent intent=new Intent(SanActivity.this,SecondActivity.class);setResult(200);finish();
4.数据库中修改
@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {    if (requestCode==200&&resultCode==200){        list.clear();        List<Book> list1 = DaoMangger.getIntance(SecondActivity.this).getDap().queryBuilder().list();        list.addAll(list1);        la.notifyDataSetChanged();    }}
二。分享
1.带面板分享
UMImage umImage = new UMImage(MainActivity.this, R.mipmap.ic_launcher);new ShareAction(MainActivity.this)        .withText("hello")        .withMedia(umImage)        .setDisplayList(SHARE_MEDIA.QQ)        .setCallback(new UMShareListener()
2.不带面板
UMImage umImage1 = new UMImage(MainActivity.this, R.mipmap.ic_launcher);new ShareAction(MainActivity.this)        .setPlatform(SHARE_MEDIA.QQ)//传入平台        .withText("hello")//分享内容        .withMedia(umImage1)        .setCallback(new UMShareListener()
3.登陆
UMShareAPI.get(this).getPlatformInfo(this, SHARE_MEDIA.QQ, new UMAuthListener()
4.获取QQ头像
在下面有Map集合的方法中写
  Iterator<Map.Entry<String, String>> iterator = map.entrySet().iterator();while (iterator.hasNext()) {    Map.Entry<String, String> next = iterator.next();    String key = next.getKey();    String value = next.getValue();        if (key.equals("iconurl")){    Intent in = new Intent(MainActivity.this, Main2Activity.class);    in.putExtra("url", value);    startActivity(in);

volley:

public class Utils {    private static Utils utils;    private RequestQueue queue;    private Utils(Context context){       queue = Volley.newRequestQueue(context);    }    public static Utils getIntance(Context context){        if (utils==null){            utils=new Utils(context);        }        return utils;    }    public void sendPost(String url, Response.Listener<String> listener,Response.ErrorListener errorListener){        StringRequest stringRequest = new StringRequest(url, listener, errorListener);        queue.add(stringRequest);    }}
okhttp:

public class Utils {    private static Utils utils;    private OkHttpClient okHttpClient;    private Utils(){        okHttpClient=new OkHttpClient();    }    public static synchronized Utils getIntance(){        if (utils==null)            utils=new Utils();        return utils;    }    public void sendGet(String url, Callback callback){         Request builder = new Request.Builder().url(url).build();         Call call = okHttpClient.newCall(builder);        call.enqueue(callback);    }}