こんにちは、この初心者の質問をご覧いただきありがとうございます。
私の問題に関連するあらゆる種類の答えを探しましたが、私が抱えている問題を見つけることができないか、私が間違っていることを誰かに説明してもらう必要があるかもしれません.
とにかく、私の問題は、インテントを学習し、putExtra、getExtra などのアクティビティ間でデータを渡しようとしていることです。そのため、選択した日付を日付ピッカーから新しいアクティビティに渡すだけの機能を備えた非常に単純なアプリを作成しました。そしてそれを画面に表示します。ボタンをクリックして次のアクティビティを開始すると「android.content.res.Resources$NotFoundException」が発生するので、何か間違ったことをしているに違いありません。他の回答された質問とは異なるコードを試しましたが、役に立ちませんでした。 ?. 私のコードは以下のとおりです。ご回答いただきありがとうございます。
最初の活動
package date.Picker;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.DatePicker;
public class DatePickerActivity extends Activity {
int year;
int month;
int day;
Button selectButton;
DatePicker datePicker;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datePicker = (DatePicker) findViewById(R.id.datePicker);
selectButton = (Button) findViewById(R.id.selectButton);
selectButton.setOnClickListener(new OnClickListener()
{
public void onClick(View v){
Intent intent = new Intent(getApplicationContext(), datePickerResult.class);
month = datePicker.getMonth();
day = datePicker.getDayOfMonth();
year = datePicker.getYear();
intent.putExtra("year",year);
intent.putExtra("month",month);
intent.putExtra("day",day);
startActivity(intent);
}
});
}
}
第二の活動
package date.Picker;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
public class datePickerResult extends Activity {
int year;
int month;
int day;
TextView textView1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dpresult);
textView1 = (TextView)findViewById(R.id.textView1);
Bundle extras = getIntent().getExtras();
extras.getBundle("year");
extras.getBundle("day");
extras.getBundle("month");
textView1.setText(year);
}
}
ですから、あなたが持っている答えや助けに感謝します。少し時間の無駄だったらごめんなさい。