Android Activity gives Popupwindow value

Source: Internet
Author: User

Features: Click on a button on the activity page to play the custom Popupwindow page and pass the phone number string from the activity to the Popupwindow page. Click the button on the Popupwindow page to jump directly to the Android Dial-up page, and the phone number is also on the page.

Declaration: The value passed its utility is the global variable of Android.

The code in the global variables class is as follows:

Package com.cn.gordon.exhibition.walk.application;

Import android.app.Application;

Public final class Globalvaries extends application {
Private String Telnum;

Public String Gettelnum () {
return telnum;
}

public void Settelnum (String telnum) {
This.telnum = Telnum;
}

@Override
public void OnCreate () {
Telnum = "";
Super.oncreate ();
}
}

The use of global variables requires a declaration in Androidmenifest.xml:

<application
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme"
Android:allowbackup= "true"
Android:name= "Com.cn.gordon.exhibition.walk.application.GlobalVaries" >
<activity
Android:name= ". Loadingactivity "
android:screenorientation= "Portrait"
Android:theme= "@android: Style/theme.black.notitlebar" >
<intent-filter>

......... The above is part of the code, where Android:name= "Com.cn.gordon.exhibition.walk.application.GlobalVaries" is the declaration of the use of global variables.

The following is the Mybusicardholderactivity page layout called Popupwindow, with the name: Mybusicardholder.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"
android:background= "#FFFFFFFF" >

<relativelayout
Android:layout_width= "Match_parent"
android:layout_height= "50dip"
android:background= "#FF333333" >

<textview
Android:layout_width= "Wrap_content"
android:layout_height= "Wrap_content"
Android:layout_centerinparent= "true"
android:text= "@string/mybusinesscardholder"
Android:textcolor= "#FFFFFFFF"
Android:textsize= "20sp"/>

<button
Android:layout_width= "80dip"
android:layout_height= "50dip"
Android:id= "@+id/btn_menu"
android:background= "@drawable/btn_login_back"
/>
<button
Android:layout_width= "30dip"
android:layout_height= "30dip"
Android:id= "@+id/btn_query"
Android:layout_centervertical= "true"
Android:layout_alignparentright= "true"
android:layout_marginright= "20dip"
android:background= "@drawable/querybtn_pressed_bg"/>
</RelativeLayout>
<listview
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:id= "@+id/mybusicardlistview"
android:divider= "@color/lightgray"
android:dividerheight= "1dip"
Android:footerdividersenabled= "true"
Android:headerdividersenabled= "true"
>
</ListView>
</LinearLayout>

The source code in Mybusicardholderactivity is as follows:

/**
* @author Seawin Dragon
*/
Package com.cn.gordon.exhibition.walk.activity;

Import java.util.ArrayList;
Import Java.util.HashMap;

Import com.cn.gordon.exhibition.walk.application.GlobalVaries;
Import Com.cn.gordon.exhibition.walk.entity.MyBusiCardHolderBean;
Import Com.cn.gordon.exhibition.walk.popup.BusicardPopupWindow;

Import android.app.Activity;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.widget.AdapterView;
Import Android.widget.AdapterView.OnItemClickListener;
Import Android.widget.ListView;
Import Android.widget.SimpleAdapter;
Import Android.widget.Toast;

/**
* @author Seawin Dragon
*
*/
public class Mybusicardholderactivity extends Activity {
Private ListView ListView;
Private Simpleadapter Simpleadapter;

Private String Telnum;

Private ProgressDialog PD;

@Override
protected void onCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.mybusicardholder);
Globalvaries globaltelnum = (globalvaries) getapplication ();
Init (globaltelnum);
Setaction ();
}

/**
* @author  seawin Dragon
* @param globaltelnum
*/
public void init (final globalvaries globaltelnum) {

ListView = (ListView) Findviewbyid (R.id.mybusicardlistview);
arraylist List = This.getitem ();
Simpleadapter = new Simpleadapter (this,list, R.layout.busicardlistviewitem, New string[]{"CompanyName", " Getcardtime "," Exhibitionname "," Companyphonenum "}, New Int[]{r.id.companyname,r.id.getcardtime, R.id.exhibitionname,r.id.companyphonenum});
//btnmenu = (Button) Findviewbyid (R.id.btn_menu);
//btnsubmit = (Button) Findviewbyid (R.ID.SUBMIT_BTN);
Listview.setadapter (Simpleadapter);
Listview.setonitemclicklistener (New Onitemclicklistener () {

@Override
public void Onitemclick (adapterview<?> arg0, View arg1, int arg2,
Long Arg3) {
arraylist<mybusicardholderbean> list = Getmylist ();
Mybusicardholderbean bean = new Mybusicardholderbean ();
Busicardpopupwindow BPW = new Busicardpopupwindow (mybusicardholderactivity.this);
int[] location = new INT[2];
Arg1.getlocationonscreen (location);
Bean = List.get (arg2);
Telnum = Bean.getcompanyphonenum ();
Bpw.showatlocation (Getcurrentfocus (), 0,location[0]+150, location[1]+20);
Globaltelnum.settelnum (telnum.substring (3, Telnum.length ()));
Toast.maketext (Mybusicardholderactivity.this, telnum.substring (3, Telnum.length ()), Toast.length_short). Show ();
}
});
}

Private Arraylist<mybusicardholderbean> getmylist () {
arraylist<mybusicardholderbean> list = new arraylist<mybusicardholderbean> ();
Mybusicardholderbean Mbchbean = new Mybusicardholderbean ();
Mbchbean.setcompanyname ("Shenzhen Valley Information Technology Co., Ltd.");
Mbchbean.setgetcardtime ("2014.08.11 11:52:08");
Mbchbean.setexhibitionname ("Internet of Things Exposition");
Mbchbean.setcompanyphonenum ("Tel: 0755-26711633");
List.add (0, Mbchbean);
Mybusicardholderbean mbchBean1 = new Mybusicardholderbean ();
Mbchbean1.setcompanyname ("Datang Telecom technology sub-Branch Co., Ltd.");
Mbchbean1.setgetcardtime ("2014.08.11 12:20:05");
Mbchbean1.setexhibitionname ("Internet of Things Exposition");
Mbchbean1.setcompanyphonenum ("Tel: 010-58919000");
List.add (1, mbchBean1);
Mybusicardholderbean mbchBean2 = new Mybusicardholderbean ();
Mbchbean2.setcompanyname ("Tianjin zhongxing Zhi Lian Technology Co., Ltd.");
Mbchbean2.setgetcardtime ("2014.08.11 08:50:12");
Mbchbean2.setexhibitionname ("Internet of Things Exposition");
Mbchbean2.setcompanyphonenum ("Tel: 022-84809202");
List.add (2, mbchBean2);
Mybusicardholderbean mbchBean3 = new Mybusicardholderbean ();
Mbchbean3.setcompanyname ("United States Yi Lian Technology Co., Ltd.");
Mbchbean3.setgetcardtime ("2014.08.11 08:50:12");
Mbchbean3.setexhibitionname ("Internet of Things Exposition");
Mbchbean3.setcompanyphonenum ("Tel: +86-21-62122066");
List.add (3, MBCHBEAN3);
Mybusicardholderbean mbchBean4 = new Mybusicardholderbean ();
Mbchbean4.setcompanyname ("Shenzhen de Card Technology Co., Ltd.");
Mbchbean4.setgetcardtime ("2014.08.11 08:20:12");
Mbchbean4.setexhibitionname ("Internet of Things Exposition");
Mbchbean4.setcompanyphonenum ("Tel: 400-888-7816");
List.add (4, MBCHBEAN4);
return list;
}
Public arraylistarraylistMybusicardholderbean Mbchbean = new Mybusicardholderbean ();
for (int i = 0; i < getmylist (). Size (); i++) {
Mbchbean = Getmylist (). get (i);
hashmap<string, object> map = new hashmap<string, object> ();
Map.put ("CompanyName", Mbchbean.getcompanyname ());
Map.put ("Getcardtime", Mbchbean.getgetcardtime ());
Map.put ("Exhibitionname", Mbchbean.getexhibitionname ());
Map.put ("Companyphonenum", Mbchbean.getcompanyphonenum ());
Item.add (map);
}
return item;
}

}

Here is the page layout of Popupwindow, name: Popupwindow_busicardholder.xml

<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
android:orientation= "Horizontal"
Android:layout_width= "180dip"
android:layout_height= "50dip"
android:gravity= "Center"
android:background= "@drawable/LAYOUT_SUB_ITEMPRESS_BG"
>
<button
Android:layout_width= "60dip"
android:layout_height= "50dip"
Android:id= "@+id/dailphonenumber"
android:layout_gravity= "Center"
android:background= "@drawable/BUSICARDHOLDER_PHONECALL_PRESS_BG" >
</Button>
<button
Android:layout_width= "60dip"
android:layout_height= "50dip"
Android:id= "@+id/checkbusicard"
android:layout_gravity= "Center"
android:background= "@drawable/BUSICARDHOLDER_CHECKCARD_PRESS_BG" >
</Button>
<button
Android:layout_width= "60dip"
android:layout_height= "50dip"
Android:id= "@+id/checkcompany"
android:layout_gravity= "Center"
android:background= "@drawable/BUSICARDHOLDER_PHONECALL_PRESS_BG" >
</Button>
</LinearLayout>

Here is Popupwindow, the name is: Busicardpopupwindow

Package com.cn.gordon.exhibition.walk.popup;

Import COM.CN.GORDON.EXHIBITION.WALK.ACTIVITY.R;
Import com.cn.gordon.exhibition.walk.application.GlobalVaries;

Import android.app.Activity;
Import Android.content.Context;
Import android.content.Intent;
Import android.graphics.drawable.ColorDrawable;
Import Android.net.Uri;
Import Android.view.LayoutInflater;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.PopupWindow;
Import Android.widget.RelativeLayout.LayoutParams;

public class Busicardpopupwindow extends Popupwindow {
Private View Contentview;

Private String telnum= "";
Public Busicardpopupwindow (final Activity context) {
Layoutinflater Inflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);
Contentview = inflater.inflate (R.layout.popupwindow_busicardholder, NULL);
int h = Context.getwindowmanager (). Getdefaultdisplay (). GetHeight ();
int w = Context.getwindowmanager (). Getdefaultdisplay (). GetWidth ();
Set the view of Selectpicpopupwindow
This.setcontentview (Contentview);
Sets the width of the Selectpicpopupwindow pop-up form
This.setwidth (W/2 + 50);
Sets the height of the Selectpicpopupwindow pop-up form
This.setheight (layoutparams.wrap_content);
Set the Selectpicpopupwindow pop-up form to click
This.setfocusable (TRUE);
This.setoutsidetouchable (TRUE);
Refresh Status
This.update ();
Instantiate a colordrawable color as translucent
Colordrawable DW = new colordrawable (0000000000);
Point back and other places to make it disappear, set this to trigger Ondismisslistener, set other control changes and other actions
This.setbackgrounddrawable (DW);
Mpopupwindow.setanimationstyle (Android. R.style.animation_dialog);
Set Selectpicpopupwindow pop-up form animation effect
This.setanimationstyle (R.style.animationpreview);
Button Btn_dailnumber = (button) Contentview.findviewbyid (R.id.dailphonenumber);
Button Btn_checkcard = (button) Contentview.findviewbyid (R.id.checkbusicard);
Button Btn_checkcompany = (button) Contentview.findviewbyid (R.id.checkcompany);
Btn_dailnumber.setonclicklistener (New Onclicklistener () {
Final Globalvaries Globaltelnum = (globalvaries) context.getapplication ();
@Override
public void OnClick (View v) {
if (globaltelnum!=null) {

Telnum = Globaltelnum.gettelnum ();
}
Uri uri = Uri.parse ("Tel:" +telnum);
Intent Intent = new Intent (Intent.action_dial,uri);
V.getcontext (). StartActivity (Intent);
BusicardPopupWindow.this.dismiss ();
}
});
Btn_checkcard.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
BusicardPopupWindow.this.dismiss ();
}
});

Btn_checkcompany.setonclicklistener (New Onclicklistener () {
@Override
public void OnClick (View v) {
BusicardPopupWindow.this.dismiss ();
}
});
}
public void Showpopupwindow (View parent) {
if (!this.isshowing ()) {
The following pull mode shows Popupwindow
This.showasdropdown (parent, Parent.getlayoutparams (). WIDTH/2, 18);
} else {
This.dismiss ();
}
}
}

This article mainly tells the activity to pass the data to the Popupwindow through the global variable. For reference only. Also thank those who selfless to the Internet to send technology stickers of children's shoes.

Reference: http://blog.csdn.net/feiyangxiaomi/article/details/9966215

http://blog.csdn.net/junjieking/article/details/7352571

http://blog.csdn.net/l_serein/article/details/6398342

http://bbs.csdn.net/topics/360052162

http://www.oschina.net/question/157182_46417

No matter what problems you encounter, can not solve, then find ANDROIDAPI.

Android Activity gives Popupwindow value

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.