我正在学习Android,而且我遇到了一个涉及调用自定义内容提供商的问题.我一直在教学书中使用一个例子,虽然它描述了如何创建自定义提供者,但没有明确的例子如何调用其中的特定方法.我特别研究如何从自定义内容提供程序中删除单个记录.
以下是自定义内容提供程序(EarthquakeProvider.java)的代码:
@Override
public int delete(Uri uri, String where, String[] whereArgs) {
int count;
switch (uriMatcher.match(uri)) {
case QUAKES:
count = earthquakeDB.delete(EARTHQUAKE_TABLE, where, whereArgs);
break;
case QUAKE_ID:
String segment = uri.getPathSegments().get(1);
count = earthquakeDB.delete(EARTHQUAKE_TABLE, KEY_ID + "="
+ segment
+ (!TextUtils.isEmpty(where) ? " AND ("
+ where + ')' : ""), whereArgs);
break;
default: throw new IllegalArgumentException("Unsupported URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
Run Code Online (Sandbox Code Playgroud)
我试图从主活动中调用delete方法来删除单个条目,而不是整个数据库.我想对OnLongClickListener主活动中数组列表视图中显示的选定记录使用about a.
这是我迄今为止在这个方法的主要活动中提出的:
earthquakeListView.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean …Run Code Online (Sandbox Code Playgroud) android android-contentresolver android-contentprovider onlongclicklistener
我正在尝试从Android应用程序中的Web URL保存图像,但是当我运行它时,日志cat会抛出一个异常,说它是"只读".我不知道最近发生了什么.
这是我的下载类:
public class ImageDownload {
public static void downloader(String imageURL, String fileName) {
try {
URL url = new URL("http://www.exampleurl.com/" + imageURL);
File file = new File(fileName);
URLConnection con = url.openConnection();
InputStream is = con.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(baf.toByteArray());
fos.close();
} catch (IOException e) {
Log.d("Downloader", "Error: " + e);
}
} …Run Code Online (Sandbox Code Playgroud) android urlconnection filenotfoundexception fileoutputstream
android ×2