我有一個片段定義爲訪問兒童
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;
}
}
如何從訪問的EditText我的主要活動。
我想在一些地方設置文本在EDITTEXT,但是我得到空指針在ragAdapter myAdapter =(FragAdapter)mPager.getAdapter(); AddValue screen =(AddValue)myAdapter.getItem(myPosition); EditText box =(EditText)screen.getView()。findViewById(R.id.editBox); –
我做語音識別,其onActivityResult我在的EditText –