我正在为我的学校项目编写一个Android应用程序,但我被困在这里.问题是我必须访问一个SharedPreferences值并在AsyncTask类中需要它.当我尝试访问它时,由于上下文,它不会让我.我怎样才能达到我SharedPreferences的目标AsyncTask?
public class CheckAccess extends AsyncTask<JSONObject, Integer, Boolean>{
@Override
protected Boolean doInBackground(JSONObject... params) {
//Trying to get sharedpreferences here wont work.
return null;
}
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用canvas在android/java中创建雨动画.
问题是雨后的雨滴走出屏幕,它们重新出现在空中,而不是出现在云端.
我想要的是,它们应该出现在云层中,每排雨滴之间的距离应该保持不变.
但是,在它们离开屏幕后,每行之间的距离会发生变化,并且它们会相互堆叠.
我该如何解决这个问题?
counter = 0;
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 10; j++) {
if(yrain[counter]<c.getHeight()){
yrain[counter] = 400+ yAdder[counter] +j*50;
yAdder[counter]+=rainSpeed;
}else{
yAdder[counter]=0;
yrain[counter] = 400+ yAdder[counter];
}
xrain[counter] = 300+ ((50) * i);
c.drawBitmap(rain[counter], xrain[counter], yrain[counter],null);
counter++;
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个字符串"thisisanexample".我想把它分成例如4个char数组,如下所示:
group[0]="this"
group[1]="isan"
group[2]="exam"
group[3]="ple"
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
编辑:
String str = "thisisanexample";
String[] arr = str.split("(?<=\\G.{4})");
c.drawText(arr[0], 100, 100, textPaint);
c.drawText(arr[1], 100, 200, textPaint);
c.drawText(arr[2], 100, 300, textPaint);
Run Code Online (Sandbox Code Playgroud) 我希望我的活动显示3秒的屏幕,然后返回上一屏幕.但是当我使用时
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome_layout);
TextView tvResult = (TextView)findViewById(R.id.textView1)
Thread.sleep(3000);
Intent i = new Intent(this,myActivity.class);
startActivity(i);
Run Code Online (Sandbox Code Playgroud)
但不幸的是,这不起作用.这个doesent显示活动等待3秒并返回.但是,我希望它在返回之前显示其内容.我该怎么做 ?