在一個組件中調用其他組件的內容||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);
        }
    }
});

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章