1.控件的优化:
private class ViewHolder
{
ImageView ivMap;
ImageView ivChat;
ImageView ivEye;
}
2.对listview进行优化后在getview(int position, View convertView, ViewGroup parent)的方法中:
//区分listview上item不同位置的聊天按钮的点击事件,每个聊天按钮和它所对应的位置一一对应
holder.ivChat.setTag(position);
holder.ivEye.setTag(position);
holder.ivMap.setTag(position);
3.点击事件中:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_mylings_chat:
startLingStatus(v, LingStatusActivity.INDEX_CHAT);
break;
case R.id.iv_mylings_map:
startLingStatus(v, LingStatusActivity.INDEX_MAP);
break;
case R.id.iv_myling_history_eye:
startLingStatus(v, LingStatusActivity.INDEX_TEMP);
break;
}
}
4.点击方法实现:
private void startLingStatus(View v, int page) {
//被点击的控件得到其对应的行号
int eyePosition = (Integer) v.getTag();
//根据行号得到对应的对象
MyLingInfo ling = mMyLingsList.get(eyePosition);
//触发相对应的点击事件界面的启动
LingStatusActivity.actionStart(getActivity(), ling, page);
}