アクティビティを開いて結果を返すために別のインテントを使用すると、以前のアクティビティからインテントエキストラを保存できません。メインアクティビティに戻るときに結果を保存しながら複数のインテントエキストラを収集する
ロジック:
- アクティビティA:チェックボックスから文字列を受信し、アクティビティBに渡す意図hasExtraを使用
- アクティビティB:アクティビティCへボタンで編集するテキストフィールドのリスト
- アクティビティC :インテントを余分に使用して文字列を取得し、アクティビティbの別のeditTextFieldに渡す
問題は、aからbへのintentExtraを失うことです。
私の説明が徹底的でない場合はお詫び申し上げますが、私はJavaを初めて使用しています。私はこの記事はかもしれないと思う
アクティビティA
public class PipesInspection extends AppCompatActivity{
private static final String TAG = "PipesInspection";
ArrayList<String> pipesInspectionSelection = new ArrayList<String>();
Button nextButtonToPost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.residential_pipes_inspection_lv_selected);
Log.d(TAG, "onCreate: starting");
initialiseWidgets();
}
public void initialiseWidgets(){
nextButtonToPost = (Button) findViewById(R.id.nextButton);
nextButtonToPost.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String final_category_selection = "";
for (String Selections : pipesInspectionSelection){
final_category_selection = final_category_selection + Selections + ", ";
}
Log.v(TAG,"gotten text: " + final_category_selection);
String selectedChoices = pipesInspectionSelected.getText().toString();
Intent pipesInspectionIntent = new Intent(v.getContext(), PostAJobActivity.class);
pipesInspectionIntent.putExtra("selectedChoices", selectedChoices);
v.getContext().startActivity(pipesInspectionIntent);
}
});
}
}
アクティビティB
public class PostAJobActivity extends AppCompatActivity {
private static final String TAG = "PostAJobActivity";
EditText jobTitle, jobDescription, jobLocation;
String location, title;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_post_a_job);
Log.d(TAG, "onCreate: starting");
jobDescription = (EditText)findViewById(R.id.input_job_description);
mapsButton = (ImageButton) findViewById(R.id.mapButton);
mapsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(mContext, LaunchMapsActivity.class);
startActivity(intent);
}
});
getIntentExtras();
}
public void getIntentExtras(){
jobLocation = (EditText) findViewById(R.id.location);
Intent intentLocation =getIntent();
location= intentLocation.getStringExtra("location");
jobLocation.setText(location);
jobTitle = (EditText) findViewById(R.id.title);
Intent pipesInspectionIntent = getIntent();
title = pipesInspectionIntent.getStringExtra("selectedChoices");
jobTitle.setText(title);
}
}
アクティビティC
public class PlaceListAdapter extends RecyclerView.Adapter<PlaceListAdapter.PlaceViewHolder> {
private Context mContext;
private PlaceBuffer mPlaces;
public PlaceListAdapter(Context context, PlaceBuffer places) {
this.mContext = context;
this.mPlaces = places;
}
@Override
public PlaceViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
// Get the RecyclerView item layout
LayoutInflater inflater = LayoutInflater.from(mContext);
View view = inflater.inflate(R.layout.maps_item_place_card, parent, false);
return new PlaceViewHolder(view);
}
@Override
public void onBindViewHolder(final PlaceViewHolder holder, int position) {
String placeName = mPlaces.get(position).getName().toString();
String placeAddress = mPlaces.get(position).getAddress().toString();
holder.nameTextView.setText(placeName);
holder.addressTextView.setText(placeAddress);
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentLocation = new Intent(v.getContext(), PostAJobActivity.class);
intentLocation.putExtra("location",holder.nameTextView.getText().toString()+
", " + holder.addressTextView.getText().toString());
v.getContext().startActivity(intentLocation);
}
});
}
パイプインスペクトセレクション.getText()。toString()に渡す正しい値がありますか? – roostertech
@roostertechはいそれを行う –