关于activity绑定的dialog的用法

来源:互联网 发布:韩顺平js笔记 编辑:程序博客网 时间:2024/05/05 21:20


当有的activity有返回建的时候,我们可以设置点击返回显示弹出dialog的消息,然后去dialog处理,是返回主页面,还是结束当前的activity都可以


public class ExitNoDateDialog extends Dialog{



//dailog
private Context context;
public ExitNoDateDialog(Context context) {
super(context);
this.context = context;

}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);//弹出窗体
getWindow().setBackgroundDrawableResource(android.R.color.transparent);
setContentView(R.layout.exitnodatadialog);

TextView exit = (TextView) findViewById(R.id.exit);
TextView noexit = (TextView) findViewById(R.id.noexit);

exit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
dismiss();
if(context instanceof AddOrderActivity){//if判断,如果这个activity在当前的activity,点击回退,就回到主页
Intent intent = new Intent(context,
WalletMainActivity.class);
context.startActivity(intent);
}else{
((Activity) context).finish();//否则就回到上一个activity,这里思路有很多各自发挥,大概都是在这处理,如果你不想在dialog处理也可以
}
}
});
noexit.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
dismiss();

}
});
}




}


XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/rec_radius_bg"
        android:orientation="vertical" >


        <TextView
            android:id="@+id/tv_msg"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:gravity="center"
            android:text="是否放弃该模块信息填写?"
            android:textColor="@color/text_color"
            android:textSize="18sp" />


        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="#3468FE" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >


            <TextView
                 android:id="@+id/noexit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:layout_weight="1.0"
                android:layout_gravity="center_vertical"
                android:gravity="center"
                android:text="否"
                android:textColor="#3468FE"
                android:textSize="18sp" />


            <View
                android:layout_width="1dp"
                android:layout_height="match_parent"
                android:background="#3468FE"/>


            <TextView
                android:id="@+id/exit"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                 android:layout_margin="10dp"
                android:layout_weight="1.0"
                android:layout_gravity="center_vertical"
                android:gravity="center"
                android:text="是"
                android:textColor="#3468FE"
                android:textSize="18sp" />
        </LinearLayout>
    </LinearLayout>


</LinearLayout>


主页的activity

public class AddOrderActivity extends Activity implements
MySpinnerOnSelectedListener {


public static String city = "上海";
public static double curX = 0;
public static double curY = 0;
private Date date;
private String dateTime;
private String carcolor1ID, carcolor2ID, Brand, Series;
private String province = null;
private String district = null;
private String province_code = null;
private PopupWindow pop = null;
private LinearLayout ll_popup, edt_frll;
private String city_code = null;
private String province_name = null;
private String city_name = null;
private String county_name = null;
private String[] cardItems = null;
private EditText edt_playingtime;
private GridAdapter mGridadapter;
static BDLocation lastLocation = null;
private ImageView back;
private GridView noScrollgridview;
private EditText modifiedED, ExpectedPriceED,edt_cardNum,DPprice;
private Button caraddBT;
private ImageView imageview;
// private EditText edt_bigmerNo;
private EditText cardType_sp;
private EditText edt_fr;
private EditText edt_jingYMJ;
private EditText edt_jingYRS;
private View parentView;
private EditText edt_conpanyAddr;
private TextView addImg;
private TextView activity_selectimg_send;
private EditText edt_zhengJCode, cardType_spr;
private Spinner loantype_spr;
public static AddOrderActivity merchantInfo2Activity;
private TextView tv_next, title;
private String[] loantype_sprItems = null;
public static Bitmap bimap;
    private String allname;
    private String ForwardImg;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


Res.init(this);


bimap = BitmapFactory.decodeResource(getResources(),
R.drawable.icon_addpic_unfocused);


// PublicWay.activityList.add(this);
parentView = getLayoutInflater().inflate(R.layout.addorder, null);
// setContentView(parentView);


setContentView(R.layout.addorder);
title = (TextView) findViewById(R.id.title);
title.setText("新增订单");
merchantInfo2Activity = this;


loantype_sprItems = new String[] { "1973", "1974", "1975" };
loantype_spr = (Spinner) findViewById(R.id.edt_alipayNo);
loantype_spr.setPrompt("1973");


ArrayAdapter<String> loantype_sprItemsAdapter = new ArrayAdapter<String>(
this, android.R.layout.simple_spinner_item, loantype_sprItems);
loantype_sprItemsAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// 绑定 Adapter到控件
loantype_spr.setAdapter(loantype_sprItemsAdapter);
// //获取列表数据
caraddBT = (Button) findViewById(R.id.caraddBT);
back = (ImageView) findViewById(R.id.back);
tv_next = (TextView) findViewById(R.id.next);
// tv_next.setVisibility(View.VISIBLE);
TextView tv_pro = (TextView) findViewById(R.id.serach);
// tv_pro.setVisibility(View.VISIBLE);
edt_frll = (LinearLayout) findViewById(R.id.edt_frll);
edt_fr = (EditText) findViewById(R.id.edt_fr);
edt_jingYMJ = (EditText) findViewById(R.id.edt_jingYMJ);
edt_jingYRS = (EditText) findViewById(R.id.edt_jingYRS);
edt_conpanyAddr = (EditText) findViewById(R.id.edt_merAddress);
edt_zhengJCode = (EditText) findViewById(R.id.edt_cardSite);
edt_cardNum = (EditText) findViewById(R.id.edt_cardNum);
edt_playingtime = (EditText) findViewById(R.id.edt_playingtime);
modifiedED = (EditText) findViewById(R.id.modifiedED);
ExpectedPriceED = (EditText) findViewById(R.id.ExpectedPriceED);
DPprice= (EditText) findViewById(R.id.DPprice);
edt_frll.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddOrderActivity.this,
CarTypeActivity.class);
startActivityForResult(intent, 10);
}
});
edt_fr.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddOrderActivity.this,
CarTypeActivity.class);
startActivityForResult(intent, 10);
}
});
        cardType_sp = (EditText) findViewById(R.id.cardType_spr);
        Intent intent = getIntent();
        String test =intent.getStringExtra("test");
        if(test != null)
        {
        String ModelName = intent.getStringExtra("ModelName");
        Brand = intent.getStringExtra("Brand");
        Series = intent.getStringExtra("Series");
        allname = intent.getStringExtra("carname");
        cardType_sp.setTag(intent.getStringExtra("carname"));// 型号名称
        edt_fr.setTag(Series);
        edt_fr.setText(ModelName);
        }


cardType_sp.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddOrderActivity.this,
ColorActivity.class);
startActivityForResult(intent, 2);
}
});
edt_zhengJCode.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddOrderActivity.this,
SelectAreaActivity.class);
if (city != null) {
intent.putExtra("city", city);
}
startActivityForResult(intent, 5);
}
});
edt_conpanyAddr.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(AddOrderActivity.this,
SelectAreaActivity.class);
if (city != null) {
intent.putExtra("city", city);
}
startActivityForResult(intent, 4);
}
});


SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
date = new Date(System.currentTimeMillis());


dateTime = sdf.format(date);
edt_playingtime.setText(dateTime);
edt_playingtime.setOnTouchListener(new OnTouchListener() {


@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
if (MotionEvent.ACTION_DOWN == event.getAction()) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
AddOrderActivity.this, date);
dateTimePicKDialog.dateTimePicKDialog(edt_playingtime);


dateTime = edt_playingtime.getText().toString();
}
return true;
}
});


edt_jingYMJ.setText(dateTime);
// loadSpinner();
edt_jingYMJ.setOnTouchListener(new OnTouchListener() {


@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
if (MotionEvent.ACTION_DOWN == event.getAction()) {
DateTimePickDialogUtil dateTimePicKDialog = new DateTimePickDialogUtil(
AddOrderActivity.this, date);
dateTimePicKDialog.dateTimePicKDialog(edt_jingYMJ);


dateTime = edt_jingYMJ.getText().toString();
}


return true;
}
});


back.setOnClickListener(new OnClickListener() {


@Override,
public void onClick(View v) {//这里就是点击主页的activity的返回键处理,他会跳到ExitNoDateDialog 来处理
ExitNoDateDialog noDateDialog = new ExitNoDateDialog(
AddOrderActivity.this);
noDateDialog.show();
}
});


/*
* tv_next.setOnClickListener(new OnClickListener() {

* @Override public void onClick(View v) { if
* (EditTextUtil.isEmptyEditText(edt_merpre, edt_merpre
* .getText().toString()) ||
* EditTextUtil.isEmptyEditText(edt_conpanyAddr,
* edt_conpanyAddr.getText().toString())) {

* Toast.makeText(AddOrderActivity.this, "信息填写不完整", 2000) .show(); }
* else { }

* }

* });
*/
caraddBT.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stubasd
CarEntity mCarEntity = new CarEntity();// as
if (edt_fr.getTag() != null && cardType_sp.getText() != null) {
               //   if (cardType_sp.getText() != null) {
mCarEntity.setBrand(Brand);
mCarEntity.setSeries(edt_fr.getTag().toString()); // kong
// mCarEntity.setOuterColor(carcolor1ID==null?"0":carcolor1ID);
// mCarEntity.setInnerColor(carcolor2ID==null?"0":carcolor2ID);aaa
mCarEntity.setLicenseTime("2011");
mCarEntity.setDisplayMileage(edt_jingYRS.getText()
.toString());//公里数


/*mCarEntity.setVehicleLocation(edt_zhengJCode.getText()
.toString()); // int 车辆所在地
// mCarEntity.setCooperationMethod("合作方式"); //int 合作方式
mCarEntity.setFactoryTime(edt_playingtime.getText()
.toString());// datetime
// 出厂时间
mCarEntity.setLicenseLocation(edt_conpanyAddr.getText()
.toString());
mCarEntity.setModifiedContent(modifiedED.getText()
.toString()); // string
// 改装内容*/
mCarEntity.setExpectedPrice(ExpectedPriceED.getText()
.toString());
//mCarEntity.setDpurchasePrice(DPprice.getText()
// .toString());
mCarEntity.setPlateCode(edt_cardNum.getText()
.toString());


// mCarEntity.setModelId("3919");
mCarEntity.setModelName(cardType_sp.getTag().toString());
                    mCarEntity.setForwardImg("/upload/aaaa/" +ForwardImg);
// 获取颜色
String colorname = cardType_sp.getText().toString();
if (colorname.length() > 0) {
mCarEntity.setOuterColorName(colorname.substring(0,
colorname.indexOf("/"))); // id
mCarEntity.setInnerColorName(colorname.substring(
colorname.indexOf("/") + 1, colorname.length()));
}
searchAsyncTask(mCarEntity);
} else {
Toast.makeText(getApplicationContext(), "提交数据不完整", 1000)
.show();
}
}
});


Init();


}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
for (int i = 0; i < PublicWay.activityList.size(); i++) {
if (null != PublicWay.activityList.get(i)) {
PublicWay.activityList.get(i).finish();
}
}
System.exit(0);
}
switch (keyCode) {
// case KeyEvent.KEYCODE_BACK:
// back.performClick();
// break;


case KeyEvent.KEYCODE_BACK:
for (int i = 0; i < PublicWay.activityList.size(); i++) {
if (null != PublicWay.activityList.get(i)) {
PublicWay.activityList.get(i).finish();
}
}
System.exit(0);
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}


@Override
public void getAddressInfo(String PName, String PCode, String CName,
String CCode, String CouName, String CouCode) {
province = PName;
city = CName;
district = CouCode;
province_code = PCode;
city_code = CCode;
province_name = PName;
city_name = CName;
county_name = CouName;
}


public static String getPrimaryKey() {
String key = UUID.randomUUID().toString();
return key.replaceAll("-", "");
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (data != null && requestCode == 10) {
String carname = data.getStringExtra("carname");
Brand = data.getStringExtra("Brand");
Series = data.getStringExtra("Series");
cardType_sp.setTag(data.getStringExtra("ModelName"));// 型号名称
edt_fr.setTag(Series);
           // Intent intent = getIntent();
            //String ModelName = intent.getStringExtra("ModelName");
            //carname=ModelName.replaceAll(" ", "");
edt_fr.setText(carname);
}


if (data != null && requestCode == 2) {
String carcolor = data.getStringExtra("carcolor");
carcolor1ID = data.getStringExtra("carcolor1ID");
carcolor2ID = data.getStringExtra("carcolor2ID");
cardType_sp.setText(carcolor);
}
if (data != null && requestCode == 4) {
String address = data.getStringExtra("city");
edt_conpanyAddr.setText(address);
}
if (data != null && requestCode == 5) {
String address = data.getStringExtra("city");
edt_zhengJCode.setText(address);
}
if (data != null && requestCode == TAKE_PICTURE) {
if (Bimp.tempSelectBitmap.size() < 9 && resultCode == RESULT_OK) {
String fileName = String.valueOf(System.currentTimeMillis());
Bitmap bm = (Bitmap) data.getExtras().get("data");
FileUtils.saveBitmap(bm, fileName);
                ForwardImg=fileName;
ImageItem takePhoto = new ImageItem();
takePhoto.setBitmap(bm);
Bimp.tempSelectBitmap.add(takePhoto);
}
}
super.onActivityResult(requestCode, resultCode, data);
}


private void searchAsyncTask(final CarEntity carEntity) {
new AsyncTask<Object, Object, String[]>() {


private ProgressDialog progressDialog;


@Override
protected void onPreExecute() {
super.onPreExecute();


if (progressDialog == null) {
progressDialog = new ProgressDialog(AddOrderActivity.this);
progressDialog.setCancelable(false);
progressDialog.setMessage("正在添加,请稍候...");
progressDialog.show();
}
}


@Override
protected String[] doInBackground(Object... params) {
return JsonRes.getInstance(AddOrderActivity.this).addvehicleinfosAction(AddOrderActivity.this, carEntity);
}


@Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);


if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}


if (result != null && result[0] != null
&& result[0].equals("200")) {
Toast.makeText(AddOrderActivity.this, "添加成功", 1000);


if (Bimp.tempSelectBitmap.size() >= 1) {
for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
String base64 = bitmaptoString(Bimp.tempSelectBitmap
.get(i).getBitmap());
LoginAsyncTask(result[1], base64, i + 1);


}
} else {
finish();
Intent myintent = new Intent(AddOrderActivity.this,
WalletMainActivity.class);
startActivity(myintent);
}
} else if (TextUtils.isEmpty(result[0])
&& TextUtils.isEmpty(result[1])) {


if (WalletRes.getInstance().IsNetWork(
getApplicationContext())) {
Toast.makeText(getApplicationContext(), "服务器未返回数据!",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(),
"没有网络连接,请检查网络配置!", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(getApplicationContext(), result[1],
Toast.LENGTH_SHORT).show();
}
}
}.execute();


};


private static final int TAKE_PICTURE = 0x000001;


public void photo() {
Intent openCameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(openCameraIntent, TAKE_PICTURE);
}


public void Init() {


pop = new PopupWindow(AddOrderActivity.this);


View view = getLayoutInflater().inflate(R.layout.item_popupwindows,
null);


ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);


pop.setWidth(LayoutParams.MATCH_PARENT);
pop.setHeight(LayoutParams.WRAP_CONTENT);
pop.setBackgroundDrawable(new BitmapDrawable());
pop.setFocusable(true);
pop.setOutsideTouchable(true);
pop.setContentView(view);


imageview = (ImageView) findViewById(R.id.imageview);


RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent);
Button bt1 = (Button) view.findViewById(R.id.item_popupwindows_camera);
Button bt2 = (Button) view.findViewById(R.id.item_popupwindows_Photo);
Button bt3 = (Button) view.findViewById(R.id.item_popupwindows_cancel);
parent.setOnClickListener(new OnClickListener() {


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
photo();
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(AddOrderActivity.this,
AlbumActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.activity_translate_in,
R.anim.activity_translate_out);
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt3.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
}
});
addImg = (TextView) findViewById(R.id.addImg);
noScrollgridview = (GridView) findViewById(R.id.noScrollgridview);
noScrollgridview.setSelector(new ColorDrawable(Color.TRANSPARENT));
mGridadapter = new GridAdapter(this);
mGridadapter.update();
noScrollgridview.setAdapter(mGridadapter);
noScrollgridview.setOnItemClickListener(new OnItemClickListener() {


public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
if (arg2 == Bimp.tempSelectBitmap.size()) {
// getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
// 隐藏软键盘
// parentView.setVisibility(View.INVISIBLE);


parentView.setVisibility(View.VISIBLE);
// Log.i("ddddddd", "----------");
// ll_popup.startAnimation(AnimationUtils.loadAnimation(AddOrderActivity.this,R.anim.activity_translate_in));
pop.showAtLocation(parentView, Gravity.CENTER, 0, 0);
} else {
Intent intent = new Intent(AddOrderActivity.this,
GalleryActivity.class);
intent.putExtra("position", "1");
intent.putExtra("ID", arg2);
startActivity(intent);
}
}
});


}


@SuppressLint("HandlerLeak")
public class GridAdapter extends BaseAdapter {
private LayoutInflater inflater;
private int selectedPosition = -1;
private boolean shape;


public boolean isShape() {
return shape;
}


public void setShape(boolean shape) {
this.shape = shape;
}


public GridAdapter(Context context) {
inflater = LayoutInflater.from(context);
}


public void update() {
loading();
}


public int getCount() {
if (Bimp.tempSelectBitmap.size() == 9) {
return 9;
}
return (Bimp.tempSelectBitmap.size() + 1);
}


public Object getItem(int arg0) {
return null;
}


public long getItemId(int arg0) {
return 0;
}


public void setSelectedPosition(int position) {
selectedPosition = position;
}


public int getSelectedPosition() {
return selectedPosition;
}


public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
convertView = inflater.inflate(R.layout.item_published_grida,
parent, false);
holder = new ViewHolder();
holder.image = (ImageView) convertView
.findViewById(R.id.item_grida_image);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}


if (position == Bimp.tempSelectBitmap.size()) {
holder.image.setImageBitmap(BitmapFactory.decodeResource(
getResources(), R.drawable.icon_addpic_unfocused));
if (position == 9) {
holder.image.setVisibility(View.GONE);
}
} else {
holder.image.setImageBitmap(Bimp.tempSelectBitmap.get(position)
.getBitmap());
}


return convertView;
}


public class ViewHolder {
public ImageView image;
}


Handler handler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
mGridadapter.notifyDataSetChanged();
break;
}
super.handleMessage(msg);
}
};


public void loading() {
new Thread(new Runnable() {
public void run() {
while (true) {
if (Bimp.max == Bimp.tempSelectBitmap.size()) {
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
break;
} else {
Bimp.max += 1;
Message message = new Message();
message.what = 1;
handler.sendMessage(message);
}
}
}
}).start();
}
}


public String bitmaptoString(Bitmap bitmap) {


// 将Bitmap转换成字符串


String string = null;


ByteArrayOutputStream bStream = new ByteArrayOutputStream();


bitmap.compress(CompressFormat.PNG, 100, bStream);


byte[] bytes = bStream.toByteArray();


string = Base64.encodeToString(bytes, Base64.DEFAULT);


return string;


}


private void LoginAsyncTask(final String orderid, final String base64,
final int inumber) {
new AsyncTask<Object, Object, String[]>() {
private ProgressDialog progressDialog;


@Override
protected void onPreExecute() {
super.onPreExecute();
if (progressDialog == null) {
progressDialog = new ProgressDialog(AddOrderActivity.this);
progressDialog.setMessage("正在上传图片,请稍候...");
progressDialog.show();
}
}


@Override
protected String[] doInBackground(Object... params) {
return JsonRes.getInstance(getApplicationContext())
.uploadimageAction(getApplicationContext(), orderid,
base64);
}


@Override
protected void onPostExecute(String[] result) {
super.onPostExecute(result);
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
if (result != null && result[1] != null) {
Toast.makeText(getApplicationContext(),
"第" + inumber + "张图片上传成功", Toast.LENGTH_SHORT)
.show();
// URL murl = new URL(result[1]);
// imageview.setImageURI(murl);
if (Bimp.tempSelectBitmap.size() == inumber) {
pop.dismiss();
ll_popup.clearAnimation();
Bimp.max = 0;
Bimp.tempSelectBitmap.clear();
finish();
Intent myintent = new Intent(AddOrderActivity.this,
WalletMainActivity.class);
startActivity(myintent);
}
} else {
Toast.makeText(getApplicationContext(), result[1],
Toast.LENGTH_SHORT).show();
}


}
}.execute();
};


protected void onRestart() {
mGridadapter.update();
super.onRestart();
}
}


主activity的xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_bule"
    android:orientation="vertical"
    tools:context=".MccListActivity" >


    <include
        android:layout_width="fill_parent"
        android:layout_height="@dimen/height_top_bar"
        layout="@layout/capptitle" />


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent" >


        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
            
            <LinearLayout
                
                 android:id="@+id/edt_frll"
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:background="@color/white"
                android:orientation="horizontal" >
            
                <TextView
               android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="车型:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
                
                <EditText
                    android:id="@+id/edt_fr"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                     android:focusable="false"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:background="@drawable/spinner"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="外部颜色与内部颜色:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/cardType_spr"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:focusable="false"
                    android:layout_marginLeft="10dp"
                    android:background="@null" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:visibility="gone"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="上牌时间:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/edt_jingYMJ"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:inputType="number"
                    android:maxLength="20"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:visibility="gone"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="车辆所在地:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/edt_cardSite"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:ems="10"
                    android:paddingLeft="10dp" android:focusable="false"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" >
                </EditText>
            </LinearLayout>
         <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="车牌号:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/edt_cardNum"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:maxLength="50"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="表显里程(万公里):"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/edt_jingYRS"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:inputType="numberSigned"
                    android:maxLength="6"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:background="@color/white"
                android:visibility="gone"
                android:orientation="horizontal" >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="合作方式:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <Spinner
                    android:id="@+id/edt_alipayNo"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp"/>
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="1dp"
                android:visibility="gone"
                android:background="@color/white"
                android:orientation="horizontal" >
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:singleLine="true"
                    android:text="出厂时间:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
                      <EditText
                    android:id="@+id/edt_playingtime"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:ems="10"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:visibility="gone"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawableLeft="@drawable/qs"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="牌照所在地:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/edt_merAddress"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:maxLength="50" android:focusable="false"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


            </LinearLayout>
             <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawableLeft="@drawable/qs"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="车商采购价:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/DPprice"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:maxLength="50"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:visibility="gone"
                android:background="@color/white"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawableLeft="@drawable/qs"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="心理价位:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/ExpectedPriceED"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="1.0"
                    android:background="@null"
                    android:maxLength="50"
                    android:paddingLeft="10dp"
                    android:singleLine="true"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="60dp"
                android:layout_marginTop="15dp"
                android:background="@color/white"
                android:visibility="gone"
                android:orientation="horizontal" >


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawableLeft="@drawable/qs"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="改装内容:"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <EditText
                    android:id="@+id/modifiedED"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_gravity="center_vertical"
                    android:layout_weight="0.98"
                    android:background="@null"
                    android:lines="2"
                    android:maxLength="50"
                    android:paddingLeft="10dp"
                    android:text="无"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="100dp"
                android:layout_marginTop="15dp"
                android:background="@color/white"
                android:orientation="vertical">


                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="10dp"
                    android:drawablePadding="5dp"
                    android:singleLine="true"
                    android:text="照片添加"
                    android:textColor="@color/text_color"
                    android:textSize="18sp" />


                <GridView
                    android:id="@+id/noScrollgridview"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="5dp"
                    android:horizontalSpacing="3dp"
                    android:numColumns="8"
                    android:scrollbars="none"
                    android:verticalSpacing="5dp" >
                </GridView>
            </LinearLayout>


            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="80dp"
                android:layout_marginTop="15dp"
                android:background="@color/white"
                android:orientation="horizontal" >


                <Button
                    android:id="@+id/caraddBT"
                    android:layout_width="match_parent"
                    android:layout_height="60dp"
                    android:layout_margin="20dp"
                    android:background="@drawable/tybtn"
                    android:text="确认"
                    android:textColor="@color/white"
                    android:textSize="@dimen/m_size" />
            </LinearLayout>
        </LinearLayout>
    </ScrollView>


</LinearLayout>





运行效果就这样





1 0