我想创建一个在单击菜单项后启动新活动的intent,但我不知道如何执行此操作.我一直在阅读android文档,但我的实现不正确..并且正确方向的一些指导会有所帮助.我在下面列出了我的代码并注释了我的问题区域,我想我正在调用错误的方法.
package com.jbsoft.SimpleFlashlight;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.*;
import android.view.MenuItem.OnMenuItemClickListener;
import android.widget.Button;
import android.widget.Toast;
public class SimpleFlashLightActivity extends Activity {
Button GreenButton; // Declare instances of buttons to use later
Button BlueButton;
private static final int OK_MENU_ITEM = Menu.FIRST;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
BlueButton = (Button) findViewById(R.id.bluebutton);
BlueButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//Display msg when user clicks Blue Button
showColorChangeMsg();
// …Run Code Online (Sandbox Code Playgroud) android event-handling menuitem options-menu onitemclicklistener
我发布了一个应用程序,其中一个基本功能是允许用户拍照,然后将该照片保存在其外部存储的特定文件夹中.
一切似乎都运行正常,但我现在有两个报告声称在拍照后,点击"完成"退出相机(并返回活动),应用程序被强制关闭,带来用户回到主屏幕.
这发生在Samsung Nexus S和Galaxy Tab上.下面我发布了我的代码,以显示我设置我的意图以及如何在onActivityResult()中处理保存和显示照片.任何关于在点击"完成"退出相机应用程序后可能导致崩溃的指导,将不胜感激!
同样,这似乎在大多数设备上都能正常工作,但我想知道它们是否是一种更有效,更通用的方法.谢谢
我如何解雇相机意图
case ACTION_BAR_CAMERA:
// numbered image name
fileName = "image_" + String.valueOf(numImages) + ".jpg";
output = new File(direct + File.separator + fileName); // create
// output
while (output.exists()) { // while the file exists
numImages++; // increment number of images
fileName = "image_" + String.valueOf(numImages) + ".jpg";
output = new File(outputFolder, fileName);
}
camera = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
uriSavedImage = Uri.fromFile(output); // get Uri of the output
camera.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage); //pass in Uri to camera …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Python 3内置的JSON模块进行一些简单的JSON解析,并且通过阅读关于SO和谷歌搜索的一堆其他问题,看起来这应该是非常简单的.但是,我想我得到一个字符串而不是预期的字典.
首先,这是我试图从中获取值的JSON.这只是Twitter API的一些输出
[{'in_reply_to_status_id_str': None, 'in_reply_to_screen_name': None, 'retweeted': False, 'in_reply_to_status_id': None, 'contributors': None, 'favorite_count': 0, 'in_reply_to_user_id': None, 'coordinates': None, 'source': '<a href="http://twitter.com" rel="nofollow">Twitter Web Client</a>', 'geo': None, 'retweet_count': 0, 'text': 'Tweeting a url \nhttp://t.co/QDVYv6bV90', 'created_at': 'Mon Sep 01 19:36:25 +0000 2014', 'entities': {'symbols': [], 'user_mentions': [], 'urls': [{'expanded_url': 'http://www.isthereanappthat.com', 'display_url': 'isthereanappthat.com', 'url': 'http://t.co/QDVYv6bV90', 'indices': [16, 38]}], 'hashtags': []}, 'id_str': '506526005943865344', 'in_reply_to_user_id_str': None, 'truncated': False, 'favorited': False, 'lang': 'en', 'possibly_sensitive': False, 'id': 506526005943865344, 'user': {'profile_text_color': '333333', 'time_zone': None, 'entities': {'description': …Run Code Online (Sandbox Code Playgroud) 我正在尝试向目前市场上的应用程序发布关键更新.我需要查询MediaStore中的缩略图,并将缩略图加载到GridView中.到目前为止一切都很好,现在我只需要根据我的内容(缩略图的路径)获取用户外部存储上的实际全尺寸图像的路径.每当用户点击缩略图,共享,查看,移动和删除时,我都需要能够执行4个操作...但我不能仅使用缩略图路径执行任何操作,我已经尝试了所有内容,但没有工作:/.以下是我在下面的实施片段,对此的任何帮助或指导将不胜感激!
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
int columnIndex = 0;
String[] projection = {MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, projection, null, null, null);
if(cursor != null){
columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToPosition(position);
imagePath = cursor.getString(columnIndex);
FileInputStream is = null;
BufferedInputStream bis = null;
try{
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
useThisBitmap = Bitmap.createScaledBitmap(bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
}catch(Exception e){
//Try to recover
}
finally{
try{
if(bis != null){
bis.close();
} …Run Code Online (Sandbox Code Playgroud) 我有一个ListView,显示歌曲名称和艺术家.有时,歌曲名称包含曲目编号和分隔符,其中包含一些格式
13 - J. Cole - Best Friend
Run Code Online (Sandbox Code Playgroud)
和其他人一样
13 - Beautiful People
Run Code Online (Sandbox Code Playgroud)
经过一番挖掘后,我发现最好的方法是定义一个正则表达式模式,它将删除字符串中的任何不必要的字符.凉.我在这里查看了类似主题的其他SO问题和一些博客文章,但仍然没有运气.
这是我第一次处理正则表达式时,我发现它非常有用,只是试图提出有效/有用的模式.
如果是匹配的话,这就是我需要从字符串中删除的内容
The track number
The "-" or whatever separator character that follows it
The artist name and the "-" that follows that(Each artist name is listed below the song, so it would be redundant)
Run Code Online (Sandbox Code Playgroud)
任何有关这方面的帮助都会像往常一样非常感谢,谢谢!
编辑:我想要的相同输出是这样的,只有歌曲名称.没有曲目编号,如果适用; " - "后面没有艺术家的名字
Beautiful People
Angel of Mine
Human Nature
Run Code Online (Sandbox Code Playgroud) android ×4
camera ×1
dictionary ×1
gridview ×1
java ×1
json ×1
menuitem ×1
options-menu ×1
parsing ×1
path ×1
python ×1
regex ×1
thumbnails ×1