在一个组件中调用其他组件的内容||android中怎样在activity中获取fragment中的控件

//getFragmentManager().findFragmentById(id).getView().findViewById(id); // 此句截自百度知道

详见google 官方蓝牙里BluetoothChatFragment中setupChat()方法button调用EditText中文字;

 View view = getView(); // 先设置要调用的组件
TextView textView = (TextView) view.findViewById(R.id.edit_text_out); // 拿到想要调用的组件

// Initialize the send button with a listener that for click events
mSendButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        // Send a message using content of the edit text widget
        View view = getView();
        if (null != view) {
            TextView textView = (TextView) view.findViewById(R.id.edit_text_out);
            String message = textView.getText().toString();
            sendMessage(message);
        }
    }
});

猜你喜欢

转载自blog.csdn.net/PyFanL/article/details/72817937