0
私は、時間のかかるAndroidアプリケーションをtimePickerで実行しました。選択した時刻が現在の時刻と同じ場合、アプリケーションからお知らせ。これはアンドロイドスタジオで書いたコードです:timePickerから時刻を取得して現在の時刻で確認する際の問題
public Button mb;
public EditText editText;
public Button pb;
int i=0;
public void showMotivation(){
mb = (Button)findViewById(R.id.mb);
editText = (EditText)findViewById(R.id.editText);
mb.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
editText.setText(MotivationWords());
}
}
);
}
public String MotivationWords(){
Random rnd = new Random();
List l = new LinkedList<>();
l.add("The price of excellence is discipline; the cost of mediocrity is disappointment.");
l.add("If we had no winter, the spring would not be so pleasant; if we did not sometimes taste of adversity, prosperity would not be so welcome.");
l.add("If your ship doesn’t come in, swim out to it!");
l.add("Tomorrow will be a better day ..");
l.add("Life’s not about waiting for the storms to pass... it’s about learning to dance in the rain.");
l.add("When you reach the end of your rope, tie a knot in it and hang on.");
l.add("A smooth sea never made a skilled mariner.");
l.add("Great masters merit emulation, not worship.");
l.add("Confidence is contagious. So is the lack of confidence.");
l.add("Optimism may sometimes be delusional, but pessimism is always delusional.");
i=rnd.nextInt()%9;
return l.get(i).toString();
}
public void changing(){
pb = (Button)findViewById(R.id.pb);
pb.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intb = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intb);
}
}
);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
changing();
showMotivation();
}