私は次のように定義されたフラグメントを持っています
public class AddValue extends Fragment
{
private int position;
public EditText addEdit;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Log.e("Test", "hello");
position = getArguments().getInt("position");
}
/**
* Handle the results from the voice recognition activity.
*/
@Override
public void onActivityCreated(Bundle savedInstanceState)
{
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.add_value, container, false);
addEdit = (EditText) view.findViewById(R.id.editBox);
if (position == 0)
addEdit.setHint("Patient Id");
if (position == 1)
addEdit.setHint("Age");
if (position == 2)
addEdit.setHint("Height In Inches");
if (position == 3)
addEdit.setHint("Weight in lbs");
if (position == 4)
addEdit.setHint("LA Volume Index");
return view;
}
}
私は1つを持っているMainActivity extends FragmentActivity
今私はこれを使用しています
FragAdapter myAdapter = (FragAdapter) mPager.getAdapter();
AddValue screen = (AddValue) myAdapter.getItem(myPosition);
EditText box = (EditText) screen.getView().findViewById(R.id.editBox);
public class FragAdapter extends FragmentPagerAdapter
{
public FragAdapter(FragmentManager fm)
{
super(fm);
}
@Override
public int getCount()
{
return 5;
}
@Override
public Fragment getItem(int position)
{
AddValue val = new AddValue();
Fragment frag = val;
Bundle arg = new Bundle();
arg.putInt("position", position);
frag.setArguments(arg);
return frag;
}
}
メインアクティビティからEditTextにアクセスするにはどうすればよいですか。