package com.example.fangjingdong.view.activity;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.TextView;
import com.example.fangjingdong.R;
import com.example.fangjingdong.view.fragment.FragmentDaiZhiFu;
import com.example.fangjingdong.view.fragment.FragmentQuanBu;
import com.example.fangjingdong.view.fragment.FragmentYiQuXiao;
import com.example.fangjingdong.view.fragment.FragmentYiZhiFu;
public class MyDingDan extends AppCompatActivity implements View.OnClickListener {
private ImageView detail_image_back;
private ImageView detail_share;
private RadioGroup radio_group;
private ImageView san_dian_pop;
private PopupWindow popupWindow;
private TextView pop_dai_pay;
private TextView pop_already_pay;
private TextView pop_cancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_ding_dan);
detail_image_back = (ImageView) findViewById(R.id.detail_image_back);
radio_group = (RadioGroup) findViewById(R.id.radio_group);
san_dian_pop = (ImageView) findViewById(R.id.san_dian_pop);
detail_image_back.setOnClickListener(this);
san_dian_pop.setOnClickListener(this);
initPopUpWindown();
int flag = getIntent().getIntExtra("flag", -1);
if (flag == -1) {
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentQuanBu()).commit();
}else {
//如果从fragemnt跳转过来 需要展示自己的页面
if (flag == 1) {//待支付
radio_group.check(R.id.radio_02);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentDaiZhiFu()).commit();
}else if (flag == 2) {//已支付
radio_group.check(R.id.radio_03);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiZhiFu()).commit();
}else if (flag == 3) {//已取消
radio_group.check(R.id.radio_04);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiQuXiao()).commit();
}
}
radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup radioGroup, int id) {
switch (id) {
case R.id.radio_01://全部
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentQuanBu()).commit();
break;
case R.id.radio_02://待支付
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentDaiZhiFu()).commit();
break;
case R.id.radio_03://已支付
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiZhiFu()).commit();
break;
case R.id.radio_04://已取消
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiQuXiao()).commit();
break;
}
}
});
}
private void initPopUpWindown() {
View view= View.inflate(MyDingDan.this,R.layout.order_pop_layout,null);
popupWindow = new PopupWindow(view, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true);
popupWindow.setTouchable(true);
popupWindow.setOutsideTouchable(true);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
//找到控件
pop_dai_pay = view.findViewById(R.id.pop_dai_pay);
pop_already_pay = view.findViewById(R.id.pop_already_pay);
pop_cancel = view.findViewById(R.id.pop_cancel);
pop_dai_pay.setOnClickListener(this);
pop_already_pay.setOnClickListener(this);
pop_cancel.setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.detail_image_back:
finish();
break;
case R.id.san_dian_pop://弹出pop
//判断一下当前radioGroup选中了哪一个RadioButton...设置展示的背景颜色
int checkedRadioButtonId = radio_group.getCheckedRadioButtonId();
switch (checkedRadioButtonId) {
case R.id.radio_02://待支付
pop_dai_pay.setBackgroundColor(Color.BLUE);
pop_already_pay.setBackgroundColor(Color.WHITE);
pop_cancel.setBackgroundColor(Color.WHITE);
break;
case R.id.radio_03://已支付
pop_dai_pay.setBackgroundColor(Color.WHITE);
pop_already_pay.setBackgroundColor(Color.BLUE);
pop_cancel.setBackgroundColor(Color.WHITE);
break;
case R.id.radio_04://已取消
pop_dai_pay.setBackgroundColor(Color.WHITE);
pop_already_pay.setBackgroundColor(Color.WHITE);
pop_cancel.setBackgroundColor(Color.BLUE);
break;
}
popupWindow.showAsDropDown(san_dian_pop);
break;
case R.id.pop_dai_pay://待支付
radio_group.check(R.id.radio_02);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentDaiZhiFu()).commit();
popupWindow.dismiss();
break;
case R.id.pop_already_pay://已支付
radio_group.check(R.id.radio_03);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiZhiFu()).commit();
popupWindow.dismiss();
break;
case R.id.pop_cancel://已取消
radio_group.check(R.id.radio_04);
getSupportFragmentManager().beginTransaction().replace(R.id.frame_content,new FragmentYiQuXiao()).commit();
popupWindow.dismiss();
break;
}
}
}
布局
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.fangjingdong.view.activity.MyDingDan"> <RelativeLayout android:id="@+id/detai_relative" android:layout_width="match_parent" android:layout_height="wrap_content"> <ImageView android:id="@+id/detail_image_back" android:padding="5dp" android:src="@drawable/leftjiantou" android:layout_width="40dp" android:layout_height="40dp" /> <TextView android:layout_centerInParent="true" android:text="我的订单" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/san_dian_pop" android:padding="5dp" android:layout_alignParentRight="true" android:src="@drawable/sandian" android:layout_width="40dp" android:layout_height="40dp" /> </RelativeLayout> <RadioGroup android:id="@+id/radio_group" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="40dp"> <RadioButton android:id="@+id/radio_01" android:checked="true" android:button="@null" android:gravity="center" android:textColor="@color/radio_text_color" android:text="全部" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_02" android:button="@null" android:gravity="center" android:textColor="@color/radio_text_color" android:text="待支付" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_03" android:button="@null" android:gravity="center" android:textColor="@color/radio_text_color" android:text="已支付" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> <RadioButton android:id="@+id/radio_04" android:button="@null" android:gravity="center" android:textColor="@color/radio_text_color" android:text="已取消" android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" /> </RadioGroup> <FrameLayout android:id="@+id/frame_content" android:layout_width="match_parent" android:layout_height="match_parent"> </FrameLayout> </LinearLayout>