Fragment实践之聊天窗体
2021-04-21 05:28
package com.sanliao.eim.activity.im; import com.sanliao.eim.R; import com.sanliao.eim.manager.ContacterManager; import com.sanliao.eim.manager.XmppConnectionManager; import com.sanliao.eim.model.User; import com.sanliao.eim.util.StringUtil; import android.app.Activity; import android.app.Fragment; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; public class FragChatTitle extends Fragment { private final static String TAG="FragChatTitle"; NewChatActivity activity=null; private ImageView titleBack;//返回button private TextView tvChatTitle;//对话username private ImageButton userInfo;//用户信息button private User user;// 聊天人 private String to_name; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.d(TAG, "onCreateView"); return inflater.inflate(R.layout.frag_chat_title_layout, container, false); } @Override public void onAttach(Activity activity) { super.onAttach(activity); Log.d(TAG, "onAttach"); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate"); } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Log.d(TAG, "onActivityCreated"); activity=(NewChatActivity)getActivity();//获得所在activity,并转为newchatactivity //返回button titleBack = (ImageView) getActivity().findViewById(R.id.title_back); titleBack.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { getActivity().finish(); } }); tvChatTitle = (TextView) getActivity().findViewById(R.id.to_chat_name); user = ContacterManager.getByUserJid(activity.getTo(), XmppConnectionManager .getInstance().getConnection()); if (null == user) { to_name = StringUtil.getUserNameByJid(activity.getTo()); } else { to_name = user.getName() == null ?user.getJID() : user.getName(); } tvChatTitle.setText(to_name);//将username设置到title //用户信息 userInfo = (ImageButton)activity. findViewById(R.id.user_info); userInfo.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(); intent.setClass(activity, FriendInfoActivity.class); startActivity(intent); } }); } @Override public void onStart() { super.onStart(); Log.d(TAG, "onStart"); } @Override public void onResume() { super.onResume(); Log.d(TAG, "onResume"); } @Override public void onPause() { super.onPause(); Log.d(TAG, "onPause"); } @Override public void onStop() { super.onStop(); Log.d(TAG, "onStop"); } @Override public void onDestroyView() { super.onDestroyView(); Log.d(TAG, "onDestroyView"); } @Override public void onDestroy() { super.onDestroy(); Log.d(TAG, "onDestroy"); } @Override public void onDetach() { super.onDetach(); Log.d(TAG, "onDetach"); } }
下一篇:C#3.17