import org.simple.eventbus.EventBus;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class OrderManageAdapter extends BaseListAdapter<OrderManageData2> {
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = getLayoutInflater(mContext).inflate(
R.layout.item_order_manage, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
final OrderManageData2 data = (OrderManageData2) mDatas.get(position);//实体类
holder.timeTv.setText(data.getStartTime());
holder.startTv.setText(data.getFrom());
holder.stopTv.setText(data.getTo());
holder.moneyTv.setText("¥" + String.valueOf(data.getPayPrice()));//将解析出的数据与控件相对应
holder.btnTv.setText(data.getOrderStateTitle());
holder.pBtn.setTag(data);
String orderType = data.getOrderType();//可以以解析出的数据为条件做判断,以动态改变item布局效果
if (orderType.equals("1")) {
holder.manageRealtimeTv.setText("实时");
holder.manageRealtimeTv.setTextColor(mContext.getResources()
.getColor(R.color.orange));
} else if (orderType.equals("2")) {
holder.manageRealtimeTv.setText("预约");
holder.manageRealtimeTv.setTextColor(mContext.getResources()
.getColor(R.color.green));
}
// 监听 圆圈多
if (data.getWayPointCount().toString().equals("2")) {
holder.duo.setVisibility(View.INVISIBLE);
} else {
holder.duo.setVisibility(View.VISIBLE);
}
// 监听 订单状态 显示 再次下单 或 去评价,或去付款
if (data.getOrderStateTitle().toString().equals("已完成")) {
holder.fBtn.setVisibility(View.GONE);
holder.pBtn.setVisibility(View.GONE);
holder.nextBtn.setVisibility(View.VISIBLE);
holder.nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext,
AddOrderInfoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("code", 1);
intent.putExtra("orderId", data.getId());
mContext.startActivity(intent);
}
});
} else if (data.getOrderStateTitle().toString().equals("等待付款")) {
holder.fBtn.setVisibility(View.VISIBLE);
holder.pBtn.setVisibility(View.GONE);
holder.nextBtn.setVisibility(View.GONE);
holder.fBtn.setOnClickListener(new View.OnClickListener() {//可以通过此种方式给item布局里的控件设置点击事件
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext, PayOrderActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("code", 1);
intent.putExtra("orderId", data.getId());
mContext.startActivity(intent);
}
});
} else if (data.getOrderStateTitle().toString().equals("已取消")) {
holder.fBtn.setVisibility(View.GONE);
holder.pBtn.setVisibility(View.INVISIBLE);
holder.nextBtn.setVisibility(View.VISIBLE);
holder.nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext,
AddOrderInfoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("code", 1);
intent.putExtra("orderId", data.getId());
mContext.startActivity(intent);
}
});
} else if (data.getOrderStateTitle().toString().equals("已付款")) {
holder.fBtn.setVisibility(View.GONE);
holder.pBtn.setVisibility(View.VISIBLE);
holder.nextBtn.setVisibility(View.VISIBLE);
holder.nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext,
AddOrderInfoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("code", 1);
intent.putExtra("orderId", data.getId());
mContext.startActivity(intent);
}
});
} else if (data.getOrderStateTitle().toString().equals("自动取消")) {
holder.fBtn.setVisibility(View.GONE);
holder.pBtn.setVisibility(View.INVISIBLE);
holder.nextBtn.setVisibility(View.VISIBLE);
holder.nextBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(mContext,
AddOrderInfoActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.putExtra("code", 1);
intent.putExtra("orderId", data.getId());
mContext.startActivity(intent);
}
});
} else {
holder.pBtn.setVisibility(View.INVISIBLE);
holder.nextBtn.setVisibility(View.INVISIBLE);
holder.fBtn.setVisibility(View.GONE);
}
return convertView;
}
static class ViewHolder {
// 实时的时间
@Bind(R.id.manage_time)
TextView timeTv;
// 订单状态
@Bind(R.id.manage_btn1)
TextView btnTv;
// 起点地址
@Bind(R.id.manage_start_address)
TextView startTv;
// 终点地址
@Bind(R.id.manage_stop_address)
TextView stopTv;
// 费用
@Bind(R.id.manage_money_tv)
TextView moneyTv;
// 起点图标
@Bind(R.id.start_image)
ImageView startImage;
// 终点图标
@Bind(R.id.stop_image)
ImageView stopImage;
// 再次下单
@Bind(R.id.manage_next_tv)
Button nextBtn;
// 去评价
@Bind(R.id.manage_p_tv)
Button pBtn;
// 去付款
@Bind(R.id.manage_f_tv)
Button fBtn;
@Bind(R.id.manage_realtime)
TextView manageRealtimeTv;
@OnClick(R.id.manage_p_tv)
void pingjia(View v) {
if (AppContext.getInstance().getLocationData() == null) {
Toast.makeText(
AppContext.getInstance().getApplicationContext(),
"请选择城市", Toast.LENGTH_LONG).show();
} else {
OrderManageData2 jump = (OrderManageData2) v.getTag();
EventBus.getDefault().post(jump, "gotopingjia");
}
}
// 圆圈 多
@Bind(R.id.text_duo)
TextView duo;
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
import org.simple.eventbus.EventBus;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
public class CarTypeListAdapter extends BaseListAdapter {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = null;
if (convertView == null || convertView.getTag() == null) {
convertView = getLayoutInflater(mContext).inflate(
R.layout.item_select_car_type, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
CarData stock = (CarData) mDatas.get(position);
holder.select_car_type_tv.setText(stock.getTitle());
holder.select_car_type_tv.setTag(stock);//setTag()可以传递一个object;但必须是同一个view
return convertView;
}
static class ViewHolder {
// 状态
@Bind(R.id.select_car_type_tv)
TextView select_car_type_tv;
@OnClick(R.id.select_car_type_tv)//通过setTag()的那个view再getTag()获取到那个object
void SetNoiceDetails(View v) {
EventBus.getDefault().post(v.getTag(), "car_data");
}
public ViewHolder(View view) {
ButterKnife.bind(this, view);
}
}
}
@Subscriber(tag = "car_data")
void setNoticeDetails(final CarData carData) {
AppContext.getUserInfo().setCarModels(carData.getTitle());//EventBus的用法,注意,传递的时候,参数是必须的
Intent intent = new Intent();
intent.putExtra("carid", carData.getID());
setResult(Activity.RESULT_OK, intent);
finish();
}