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

来源:互联网 发布:电力安全带实验数据 编辑:程序博客网 时间:2024/05/19 12:11

//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 eventsmSendButton.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);        }    }});

阅读全文
0 0
原创粉丝点击