1

I want the id of my button "configbutton" which is in the fragment in activity, so that i can call some method declared in activity. But i can't able to do so. Is there any way to do this. Activity class

 public class UartLoopBackActivity extends FragmentActivity implements
ActionBar.TabListener {

Button configButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data_analysis);
    configButton = (Button) findViewById(R.id.configButton);
}

Fragment class

public class DataShown extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    Log.d("3", "started");
    View rootView = inflater.inflate(R.layout.datashown, container, false);
    Log.d("3", "closed");
    Button tv = (Button) rootView.findViewById(R.id.configButton);
    return rootView;
}
}

if there is any way u know plz share the code. i want to refer to the the button which is in fragment in the activity class so that is can call a listener for that button from activity class. is it is possible. thanku

1 Answers1

0

Cant you define this button in fragment and then call activity method like this?

((YourActivityClassName)getActivity()).yourPublicMethod();
user3482211
  • 446
  • 4
  • 17