我有一个textview,当它被点击时,我在对话框中填充listView.这段代码以前工作正常,但今天却抛出了异常.
这是我的代码:
tvSelectedFont = (TextView)findViewById(R.id.lblQuoteSelectedFont);
tvSelectedFont.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ListView listView = new ListView(context);
listView.setAdapter(new ArrayAdapter<String>(context, android.R.layout.simple_list_item_1,
new String[] {"Default", "Serif", "Monospace"}));
final Dialog dialog = new Dialog(context);
dialog.setContentView(listView);
dialog.setTitle(R.string.txt_settings_QuotefontName);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selectedTypeFace = ((TextView)view).getText().toString();
tvSelectedFont.setText(selectedTypeFace);
switch(selectedTypeFace)
{
case "Serif":
selectedQuoteTypeFace = Typeface.SERIF;
break;
case "Monospace":
selectedQuoteTypeFace = Typeface.MONOSPACE;
break;
default:
selectedQuoteTypeFace = Typeface.DEFAULT;
break;
}
tvQuoteTextSample.setTypeface(selectedQuoteTypeFace, selectedQuoteFontStyle);
dialog.dismiss();
}
}); …
Run Code Online (Sandbox Code Playgroud) 我试图在本文后面实现自动完成位置搜索.
http://www.truiton.com/2015/04/android-places-api-autocomplete-getplacebyid/
我已经遵循了所有步骤,并在build.gradle文件中添加了适当的依赖项.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
}
Run Code Online (Sandbox Code Playgroud)
此处还有我的清单中的元数据部分.
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="@string/google_maps_key" />
Run Code Online (Sandbox Code Playgroud)
我也安装了所有必需的SDK组件.仍然我的android工作室无法解析以下导入中的places部分:
import com.google.android.gms.location.places.AutocompleteFilter;
import com.google.android.gms.location.places.AutocompletePrediction;
import com.google.android.gms.location.places.AutocompletePredictionBuffer;
import com.google.android.gms.location.places.Places;
Run Code Online (Sandbox Code Playgroud)
这是他们看起来的样子,因为他们找不到Places部分.
我该如何解决这个问题?我正在为我的应用程序使用SDK 19.
android google-places-api google-play-services android-studio
我使用 Swagger 创建了一个 Asp.net core 3.1 Web api 将文件上传到服务器。下面的代码工作正常:
[HttpPost("PostFile")]
public ActionResult PostFile(IFormFile uploadedFile)
{
var saveFilePath = Path.Combine("c:\\savefilepath\\", uploadedFile.FileName);
using (var stream = new FileStream(saveFilePath, FileMode.Create))
{
uploadedFile.CopyToAsync(stream);
}
return Ok();
}
Run Code Online (Sandbox Code Playgroud)
当我尝试运行它时,我得到了一个漂亮的上传按钮。
但是,现在我想使用不同的模型。它与 IFormFile 一起具有更多属性。
public class FileUploadRequest
{
public string UploaderName { get; set; }
public string UploaderAddress { get; set; }
public IFormFile File { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用此模型时,我在 Swagger 中没有看到任何可以帮助我在请求中附加文件的上传按钮。
由于某种原因,它将 IFormFile 显示为字符串。我怎样才能在这里获得上传按钮?
我正在使用PyCharm和Python 3.0,我想导入枕头模块.
从Project Interpreter安装Pillow模块时,我收到一条消息说:
ValueError: zlib is required unless explicitly disabled using --disable-zlib, aborting.
Run Code Online (Sandbox Code Playgroud)
我也尝试通过使用pip install和easy install来从命令行安装相同的命令,但是命令行也抛出相同的错误.
我试图在互联网上找到几种解决方案,但大多数都是针对Linux的.例如,这个解决方案:没有名为zlib的模块
如何在Windows和PyCharm中解决此问题?
我有一个带有上下文菜单的Non-Launcher活动.该菜单包含一个选项,可将活动添加到android主屏幕作为快捷方式.
我使用以下代码来创建快捷方式.
private void ShortcutIcon(){
Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Test");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}
Run Code Online (Sandbox Code Playgroud)
正确设置必要的权限和意图过滤器.当我运行此代码时,快捷方式已成功创建.在快捷方式单击时,活动将按预期打开.
但是,我的活动显示了一些动态数据.为此,我需要将一个小字符串变量传递给活动.
我之前尝试使用此代码setAction
(就像您将额外数据传递给正常意图启动活动一样)
addIntent.putExtra("key_primarykey", value_i_want_to_pass);
Run Code Online (Sandbox Code Playgroud)
但是,当用户点击活动内部的快捷方式时,value_i_want_to_pass
会显示Null.
一些应用程序Whatsapp
允许完全相同.您可以保存聊天的快捷方式.还有一些dialer apps
允许添加联系人作为快捷方式,以便当您点击快捷方式时,会自动启动语音呼叫.
我想知道如何将一些数据从我的快捷方式传递给我的活动.
我正在尝试开发一种机制,通过该机制我可以执行一次重试尝试的任何方法。
如果在第一次运行中遇到异常,将触发重试。
基本思想是,我将有一个用于重试逻辑的通用类,并且我想通过委托在其中传递任何方法。并且该方法将执行1次重试。
到目前为止,我已经开发了这个。
public class RetryHandler
{
Delegate _methodToRetry;
// default constructor with delegate to function name.
public RetryHandler(Delegate MethodToExecuteWithRetry)
{
_methodToRetry = MethodToExecuteWithRetry;
}
public void ExecuteWithRetry(bool IsRetryEnabled)
{
try
{
_methodToRetry.DynamicInvoke();
}
catch (Exception ex)
{
if (IsRetryEnabled)
{
// re execute method.
ExecuteWithRetry(false);
}
else
{
// throw exception
throw;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个问题:
我要传递的方法具有不同的输入参数(按参数数量和对象类型分别)和不同的输出参数。
有什么办法可以实现这一目标?基本上我想调用这样的方法:
RetryHandler rh = new RetryHandler(MyMethod1(int a, int b));
int output = (int) rh.ExecuteWithRetry(true);
RetryHandler rh2 = new RetryHandler(MyMethod2(string a)); …
Run Code Online (Sandbox Code Playgroud) 目前我有 3 个可绘制的 XML 文件,定义了 3 个单独的渐变。这些渐变在我的代码中动态设置为 imageView 的背景颜色(工作正常)。
示例:drawable\morningsky.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:bottom="4dp">
<shape>
<gradient
android:startColor="@color/blue"
android:endColor="@color/dark_blue"
android:angle="270" />
</shape>
Run Code Online (Sandbox Code Playgroud)
示例:drawable\eveningsky.xml
<?xml version="1.0" encoding="utf-8"?>
<item android:bottom="4dp">
<shape>
<gradient
android:startColor="@color/orange"
android:endColor="@color/yellow"
android:angle="270" />
</shape>
Run Code Online (Sandbox Code Playgroud)
我以这种方式在我的 imageView 中设置背景:
iv.setBackgroundResource(R.drawable.morningsky);
Run Code Online (Sandbox Code Playgroud)
一切都很好,但我真的需要为每个渐变使用多个不同的可绘制资源文件吗?有什么方法可以在一个可绘制文件中定义所有渐变,然后从我的代码中加载该渐变?
我有一个包含星期几名称,开始时间和结束时间的字符串列表:
List<String> eventList = Database.getEventsForThisWeek();
Run Code Online (Sandbox Code Playgroud)
样本数据:
Thursday (13:00 to 14:30)
Saturday (14:20 to 18:10)
Monday (09:00 to 14:25)
Saturday (11:00 to 12:30)
Run Code Online (Sandbox Code Playgroud)
我想对列表进行排序,以使星期几按升序排列。并且如果有多个记录具有相同的星期几,则开始时间也应按升序排列。
例如,排序后,上面的列表应如下所示:
Monday (09:00 to 14:25)
Thursday (13:00 to 14:30)
Saturday (11:00 to 12:30)
Saturday (14:20 to 18:10)
Run Code Online (Sandbox Code Playgroud)
排序列表的最佳方法是什么?