我是xamarin.forms开发的新手,但仍然可以从网上找到的一些教程开始我的第一步。我有一个异步任务,它从date.jsontest.com返回时间,并且我有一个计时器,该计时器递减标签中的文本。我想将异步任务放在计时器中,以便它重复自身并在标签上显示时间,但是即时通讯无法将异步lamba转换为func
这是我的代码,请帮助我,谢谢
static async Task<string> RequestTimeAsync()
{
using (var client = new HttpClient())
{
var jsonString = await client.GetStringAsync("http://date.jsontest.com/");
var jsonObject = JObject.Parse(jsonString);
return jsonObject["time"].Value<string>();
}
}
protected override async void OnAppearing()
{
base.OnAppearing();
timeLabel.Text = await RequestTimeAsync();
Device.StartTimer(TimeSpan.FromSeconds(1), () => { // i want the taks to be put
//here so that it gets repeated
var number = float.Parse(button.Text) - 1;
button.Text = number.ToString();
return number > 0;
});
}
Run Code Online (Sandbox Code Playgroud)
在计时器中重新加载内容页面可以解决问题,因此,如果有人可以帮助我,将不胜感激
我在SplashActivity中有这段代码,它请求ReadPhoneState权限来调用ASyncTask.在第一次运行时,活动结束(而不是崩溃),然后出现权限对话框.我授予权限并重新进入应用程序并正常启动.那么为什么首先在第一轮完成飞溅?
这是我的代码:
public class SplashActivity extends Activity {
boolean noConMessage = false, granted = false;
boolean firstRun;
int caller = 0;
int channelId = 0;
Bundle bundle;
String deviceId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
MyApplication.crashBundle = this.getIntent().getExtras();
final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
MyApplication.fontSize = Integer.parseInt(settings.getString(getResources().getString(R.string.textsize_key), "15").toString());
firstRun = settings.getBoolean(getResources().getString(R.string.firstRun_key), true);
deviceId = settings.getString(getResources().getString(R.string.deviceId_key), "-1");
/*if (ContextCompat.checkSelfPermission(SplashActivity.this, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED
) {
ActivityCompat.requestPermissions(SplashActivity.this, new String[]{
Manifest.permission.READ_PHONE_STATE}, 1);
Launching mLaunching = new Launching();
mLaunching.execute();
}else{
Launching mLaunching = new …Run Code Online (Sandbox Code Playgroud) 大家好,我有一个Web服务,该日期以字符串形式返回日期,例如:2016-4-10。我的Android应用程序是英语(阿拉伯语和英语),我可以将日期转换为以下格式(2016年9月,星期二),但是我无法将阿拉伯语的日期更改为:?????? ??,????? ??? 2016请帮助。
英文案例:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-d");
Date date3 = null;
try {
date3 = sdf.parse(date);
} catch (Exception e) {
}
sdf = new SimpleDateFormat("EEEE, MMMM yyyy");
String format = sdf.format(date3);
System.out.print("Result: " + format);
holder.date.setText(format);
Run Code Online (Sandbox Code Playgroud)
阿拉伯语:
Locale locale = new Locale("ar", "KW");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-d",locale); //doesnt work
Date date3 = null;
try {
date3 = sdf.parse(date);
} catch (Exception e) {
}
sdf = new SimpleDateFormat("EEEE, MMMM yyyy");
String format = sdf.format(date3);
System.out.print("Result: …Run Code Online (Sandbox Code Playgroud)