Adapter 에서 listView 를 꾸며주고
Activity 에 setAdapter 시켜주는 구조입니다.
소스가 얼마 안되니 통째로 올려보겠습니다,,,, 귀찮으시더라도 한번만 좀 봐주시길 부탁드립니다..
Adapter 의 onClick 부분 간추린 소스입니다..
public class TalkerListAdapter extends ArrayAdapter<DeviceInfo> implements OnTouchListener, OnClickListener {
private int resourceId;
private LayoutInflater inflater = null;
private Context context = null;
private MediaServiceAgent serviceAgent;
public TalkerListAdapter(Context ctx, int resourceId, List<DeviceInfo> arrays, MediaServiceAgent serviceAgent) {
super(ctx, resourceId, arrays);
this.inflater = LayoutInflater.from(ctx);
this.inflater = (LayoutInflater) ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.resourceId = resourceId;
this.context = ctx;
this.serviceAgent = serviceAgent;
}
@Override
public View getView(int position, View convertview, ViewGroup parent) {
ViewHolder viewHolder = null;
//UI 꾸며주는 부분
return convertview;
}
@Override
public void onClick(View v) {
switch (v.getId()) {
// 전화 버튼 클릭
case R.id.call_button:
Utility.showDialing(context, getItem((Integer)v.getTag()).getPhoneNumber());
break;
// 초대 버튼 클릭
case R.id.invite_button:
default:
break;
}
}
/*
* ViewHolder
*/
class ViewHolder {
public TextView deviceName = null;
public TextView state = null;
public ImageView isOnline = null;
public ImageView callButton = null;
public ImageView messageButton = null;
public Button whisperButton = null;
}
}
위 소스에서 초대 버튼이 눌렸을 때 Activity의 핸들러가 받을 수 있는 메세지를 보내고 싶습니다!!
Activity 의 Handler 부분 간추린 소스입니다.
public class TalkerListActivity extends BaseActivity {
private static final int REQUEST_TALKGROUT = 126;
private static final int SENSITIVITY_MSG_DELAY_TIME = 2000;
protected static final DeviceInfo deviceInfo = null;
private LoadingDialog mLoading = null;
private ListView mListView;
private TextView mGroupText;
private TextView mSensitivityText;
private View header;
private byte mTalkGroupType = Const.NORMAL;
private int pos;
private int top;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_talker);
mListView = (ListView)findViewById(R.id.talker_list);
mGroupText =(TextView)findViewById(R.id.talking_group_name);
mSensitivityText = (TextView)findViewById(R.id.talking_sensitivity_text);
mListView.setSelector(R.drawable.selector_non_effect);
// Progress 보이기
mLoading = null;
mLoading = new LoadingDialog(this);
mLoading.setCancelable(false);
mLoading.show();
private Handler eventHandler = new Handler() {
@SuppressWarnings("unchecked")
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case NotiEvent.REQ_FULL_TALKER_LIST:
if (msg.arg1 == Const.OK) {
talkerList = (List<DeviceInfo>)Infos.get(Infos.FULL_TALKER_LIST);
header = getLayoutInflater().inflate(R.layout.layout_talker_list_header, null, false);
TextView myName = (TextView)header.findViewById(R.id.my_name);
ImageView me = (ImageView)header.findViewById(R.id.me);
me.setImageResource(com.btb.pump.pvt.R.drawable.icon_talker_online);
String deviceId = (String)Infos.get(Infos.DEVICE_ID);
for (Iterator<DeviceInfo> it = talkerList.iterator() ; it.hasNext() ;) {
DeviceInfo value = it.next();
if (value.getDeviceId().equals(deviceId)) {
it.remove();
myName.setText(value.getDeviceName());
break;
}
}
if (mListView.getHeaderViewsCount() == 0)
mListView.addHeaderView(header, null, false);
// ArrayAdapter 연결
mListView.setAdapter(new TalkerListAdapter(TalkerListActivity.this, R.layout.layout_talker_list_row, talkerList, serviceAgent));
// Adapter 연결 후 최종 list position 을 가져와 셋팅.
mListView.setSelectionFromTop(pos, top);
// Progress 숨기기
if (null != mLoading && mLoading.isShowing())
mLoading.dismiss();
}
else {
mLoading.dismiss();
showMessageBox(R.string.exit_talkerList_msg);
}
break;
case NotiEvent.SENSITIVITY_CHANGED:
setSensitivity(msg.arg1);
if (msg.arg1 == 0) { // 연결이 종료되었다. 연결 종료를 알 수 있는 현재 방법은 이것 밖에 없다.
setDisconnectedState();
showMessageBox(R.string.disconnect_msg);
}
break;
case NotiEvent.SHOW_SENSITIVITY_MSG:
mSensitivityText.setVisibility(View.INVISIBLE);
break;
case NotiEvent.INVITE_USER_RESULT:
if (msg.arg1 == Const.OK) {
showMessageBox(R.string.invite_success);
}
else if (msg.arg1 != Const.OK) {
showMessageBox(R.string.invite_fail);
}
if (null != mLoading && mLoading.isShowing())
mLoading.dismiss();
break;
case //Adapter에서 보내준 메세지!:
mLoading = null;
mLoading = new LoadingDialog(TalkerListActivity.this);
mLoading.setCancelable(false);
mLoading.show();
default:
super.handleMessage(msg);
}
}
};
}