我有一个片段定义为
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;
}
}
我有一个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;
}
}
如何从我的 mainactivity 访问 EditText。