Reputation: 1163
Not sure how to state this correctly. I have class
TabsFragmentActivity extends FragmentActivity implements
FragmentTabHost.OnTabChangeListener, OnClickListener
Now on the first tab
StartFragment extends Fragment implements OnClickListener
I have a button which opens
WinnersFragment extends ListFragment
by
fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.addToBackStack("WINNERS_FRAGMENT");
fragmentTransaction.replace(android.R.id.tabhost, fragment2);
fragmentTransaction.commit();
Now on this Winners fragment I have a button and an edittext. I reach the button in my TabsFragmentActivity and it fires fine. However I cannot seem to reach my edittext. So in my TabsFragmentActivity I have
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.ibSearch:
LayoutInflater inflater = LayoutInflater.from(this);
final View textenter = inflater.inflate(R.layout.winners_list, null);
final EditText userinput = (EditText) textenter
.findViewById(R.id.etSearchState);
String searchState = userinput.getText().toString();
System.out.print("The input is: "+searchState);
fragment2.InitTask(searchState);
if (userinput.length() > 0) {
userinput.getText().clear();
}
break;
}
}
where WinnersFragment fragment2 = new WinnersFragment(); The fragment2.InitTask(searchState); fires but searchState is null.
I believe my issue is here but I cannot figure it out. LayoutInflater inflater = LayoutInflater.from(this); final View textenter = inflater.inflate(R.layout.winners_list, null);
Upvotes: 1
Views: 347
Reputation: 6462
The problem is here: final View textenter = inflater.inflate(R.layout.winners_list, null);
you create new View and never add it to any container in view hierarchy. You should implement onCreateView()
in your WinnersFragment
, inflate your layout there and return it. After that, this View
will be assigned to WinnersFragment
and you can find your EditText
by, for example, fragment2.getView().findViewById(R.id.etSearchState);
Upvotes: 0