Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在my main.java(android)上调用它_Java_Android - Fatal编程技术网

如何在my main.java(android)上调用它

如何在my main.java(android)上调用它,java,android,Java,Android,例如,我有一个addcredential()方法,我在表单中这样调用它 public boolean updateCredential(Credentials credentials){ boolean isSuccessful = true; SQLiteDatabase db=null; String whereStatement = Constants.LOGIN_ITEM + "="; String[] bindValues = new String[]

例如,我有一个
addcredential()
方法,我在表单中这样调用它

public boolean updateCredential(Credentials credentials){
    boolean isSuccessful = true;
    SQLiteDatabase db=null;
    String whereStatement = Constants.LOGIN_ITEM + "=";
    String[] bindValues = new String[] {credentials.getLoginItem().trim()};
    ContentValues values = new ContentValues();
    try{
        db=helper.getWritableDatabase();
        db.update(Constants.TABLE_NAME, values, whereStatement, bindValues);
        db.close();
        IsSuccessful=true;
    }finally{
        db.close();
    }
    return isSuccessful;
}

使用下面的方法调用

public void addRecord(View v){
    credentials.setLoginItem(loginItemText.getText().toString());
    Db=new Passworkeeper(this); 
    if(db.addCredential(credentials)){
        loginItemText.setText("");
        Toast.makeText(this, "Record added",Toast.LENGTH_SHORT).show();
    }
}


public boolean addCredential(Credentials credential){
    boolean isSuccessful= false;
    SQLiteDatabase = null;

    ContentValues values = new ContentValues();
    values.put(Constants.LOGIN_ITEM, credentials.getLoginItem().trim());

    Try{
        db = helper.getWritableDatabase();
        Db.insert(Constants.TABLE_NAME,null, values);
        Db.close();

        isSuccessful =true;
    }finally{
        Db.close();
    }
        Return isSuccessful;
    }
}

andoidmain是UI线程。所以使用线程或处理程序的post/postDelayed方法。mHandler=新处理程序();mHandler.postDelayed(mRunnable,5000);这段代码出现在哪个类上?我不知道如何在form.java中调用我的update方法。我的添加和删除已被删除functioning@sankyjain请帮助我首先,您的内容值为空,添加要更新的数据。例如values.put(“列名称”,valueformCredentials);那么我应该如何调用main.java呢
public void updateRecord(View v){
    credentials.setLoginItem(loginItemText.getText().toString());
    if(db.updateCredential(credentials))
    {
        Toast.makeText(this, "Record updated",Toast.LENGTH_SHORT).show();
        //show your toast
    }
    else
    {
        // updation failed
    }
}