2017-03-11 121 views
0

值這是我的主要活動:發送到我的活動

public class UploadApp extends AppCompatActivity implements StepperLayout.StepperListener{ 

private StepperLayout mStepperLayout; 
Toolbar uploadAppToolbar; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_upload_app); 

    uploadAppToolbar = (Toolbar) findViewById(R.id.uploadAppToolbar); 
    uploadAppToolbar.setTitle("Application Upload"); 

    mStepperLayout = (StepperLayout) findViewById(R.id.stepperLayout); 
    mStepperLayout.setAdapter(new UploadAppStepperAdapter(getSupportFragmentManager(), this)); 

}} 

步進適配器:

public class UploadAppStepperAdapter extends AbstractFragmentStepAdapter { 


public UploadAppStepperAdapter(@NonNull FragmentManager fm, @NonNull Context context) { 
    super(fm, context); 
} 

@Override 
public Step createStep(@IntRange(from = 0L) int position) { 
    switch (position) { 
     case 0: 
      return AppUploadStep1.newInstance(R.layout.content_app_upload_step1); 
     case 1: 
      return AppUploadStep2.newInstance(R.layout.content_app_upload_step2); 
     case 2: 
      return AppUploadStep3.newInstance(R.layout.content_app_upload_step3); 
     case 3: 
      return AppUploadStep4.newInstance(R.layout.content_app_upload_step4); 
     default: 
      throw new IllegalArgumentException("Unsupported position: " + position); 
    } 
} 

@Override 
public int getCount() { 
    return 4; 
} 

@NonNull 
@Override 
public StepViewModel getViewModel(@IntRange(from = 0) int position) { 
    //Override this method to set Step title for the Tabs, not necessary for other stepper types 
     StepViewModel.Builder builder = new StepViewModel.Builder(context); 

    switch (position) { 
     case 0: 
      builder 
         .setTitle("Information"); //can be a CharSequence instead 
      break; 
     case 1: 
      builder 
        .setTitle("Logo"); 
      break; 
     case 2: 
      builder 
        .setTitle("Sample Images"); 
      break; 
     case 3: 
      builder 
        .setTitle("Application Data"); 
      break; 
     default: 
      throw new IllegalArgumentException("Unsupported position: " + position); 
    } 
    return builder.create(); 
} 

}

我的一個片段的(AppUploadStep1):

public class AppUploadStep1 extends Fragment implements BlockingStep { 

private static final String LAYOUT_RESOURCE_ID_ARG_KEY = "messageResourceId"; 

EditText edtAppName, edtAppVersion, edtAppPlatform, edtAppCategory, edtAppDescription; 
TextInputLayout tilAppName, tilAppVersion, tilAppPlatform, tilAppCategory, tilAppDescription; 
String sAppName, sAppVersion, sAppPlatform, sAppCategory, sAppDescription; 
boolean f1, f2, f3, f4, f5; 

HttpURLConnection connection; 
BufferedReader reader; 
URL url; 
InputStream stream; 
StringBuffer buffer; 
String line; 

ProgressBar loading; 


@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
    final View v = inflater.inflate(R.layout.content_app_upload_step1, container, false); 
    getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN); 

    //initialize your UI 
    edtAppPlatform = (EditText) v.findViewById(R.id.edtAppPlatform); 
    edtAppVersion = (EditText) v.findViewById(R.id.edtAppVersion); 
    edtAppCategory = (EditText) v.findViewById(R.id.edtAppCategory); 
    edtAppDescription = (EditText) v.findViewById(R.id.edtAppDescription); 
    edtAppName = (EditText) v.findViewById(R.id.edtAppName); 

    tilAppName = (TextInputLayout) v.findViewById(R.id.tilAppName); 
    tilAppVersion = (TextInputLayout) v.findViewById(R.id.tilAppVersion); 
    tilAppPlatform = (TextInputLayout) v.findViewById(R.id.tilAppPlatform); 
    tilAppCategory = (TextInputLayout) v.findViewById(R.id.tilAppCategory); 
    tilAppDescription = (TextInputLayout) v.findViewById(R.id.tilAppDescription); 

    edtAppPlatform.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      showCustomSpinnerDialog(v, R.array.spinner_platform, R.id.edtAppPlatform); 
     } 
    }); 

    edtAppCategory.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      showCustomSpinnerDialog(v, R.array.categories, R.id.edtAppCategory); 
     } 
    }); 

    errorTrap(); 
    return v; 
} 

public static AppUploadStep1 newInstance(@LayoutRes int layoutResId) { 
    Bundle args = new Bundle(); 
    args.putInt(LAYOUT_RESOURCE_ID_ARG_KEY, layoutResId); 
    AppUploadStep1 fragment = new AppUploadStep1(); 
    fragment.setArguments(args); 
    return fragment; 
} 

我的問題是,我怎麼能得到在我的活動Fragment AppUploadStep1內的所有edittext中輸入的值?我正在使用github的步進庫創建一個註冊表單。

+0

發送

Bundle args = new Bundle(); args.putString("id", id); args.putString("title",title); args.putString("desc",des); editDialog.setArguments(args); 

是包含在該活動的片段?您的示例不清楚,因爲您似乎已從活動中刪除了大部分代碼 – Kuffs

+0

這只是來自Activity的代碼,庫在步進適配器上添加了片段..(.newInstance) –

+0

嘗試使用Communicator模式[here](http ://techblogon.com/communication-between-activity-and-fragment-example/)是一個例子 – ELITE

回答

0

到碎片和活動之間傳遞數據,你必須使用類似這樣

上保留

String title = getArguments().getString("title"); 
    String des = getArguments().getString("desc"); 
+0

捆綁包是您瞭解您的參數的存儲空間。 –