日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

android 获取弹窗的值,从弹出窗口调用的Activity 返回一个值_popupwindow_开发99编程知识库...

發(fā)布時(shí)間:2023/12/15 windows 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 android 获取弹窗的值,从弹出窗口调用的Activity 返回一个值_popupwindow_开发99编程知识库... 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

你應(yīng)該創(chuàng)建具有有限寬度和高度的透明 Activity,而不是彈出對(duì)話框。 這樣它就像對(duì)話框,然后你可以打開另一個(gè) Activity 并使用 intent.putExtra() 傳遞值

通過這種方式,你還可以使用 startActivityForResult() 和 onActivityResult() 。public class PopupWindowActivity extends Activity {

PopupWindow popwindow;

Button btnpopupopener,btnOpenActicivt;

TextView tv_result;

final static int POPRESULTcode=1;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_popup_window);

btnpopupopener=(Button)findViewById(R.id.btnpopupopen);

btnpopupopener.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

//TODO Auto-generated method stub

LayoutInflater inflator= (LayoutInflater)PopupWindowActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout vi=(LinearLayout)inflator.inflate(R.layout.layout_popup_content, null);

btnOpenActicivt= (Button)vi.findViewById(R.id.btnOpenActivity);

tv_result=(TextView)vi.findViewById(R.id.tv_result);

popwindow = new PopupWindow(vi, LinearLayout.LayoutParams.MATCH_PARENT,

LinearLayout.LayoutParams.WRAP_CONTENT);

popwindow.setContentView(vi);

btnOpenActicivt.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

//TODO Auto-generated method stub

Intent in= new Intent(PopupWindowActivity.this, SampleResultActivity.class);

startActivityForResult(in, POPRESULTcode);

}

});

popwindow.showAsDropDown(btnpopupopener);

}

});

}

@Override

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

//TODO Auto-generated method stub

super.onActivityResult(requestCode, resultCode, data);

switch(resultCode){

case POPRESULTcode:

Log.i("Result"," Getting Message From Result Activity");

tv_result.setText(data.getExtras().getString("resultstring"));

popwindow.showAsDropDown(btnpopupopener);

break;

}

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

//Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.popup_window, menu);

return true;

}

public class SampleResultActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_sample_result);

Intent in= new Intent(getApplicationContext(), PopupWindowActivity.class);

in.putExtra("resultstring","Sending Sample String as Data");

setResult(1, in);

finish();

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

//Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.sample_result, menu);

return true;

}

}

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/hello_world"/>

android:id="@+id/btnpopupopen"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/textView1"

android:layout_below="@+id/textView1"

android:layout_marginTop="24dp"

android:text="Open Popup"/>

popupWindow布局

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical">

android:id="@+id/btnOpenActivity"

style="?android:attr/buttonStyleSmall"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Go To next Activity Get Result back"/>

android:id="@+id/tv_result"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="View Result Here"

android:textAppearance="?android:attr/textAppearanceLarge"/>

總結(jié)

以上是生活随笔為你收集整理的android 获取弹窗的值,从弹出窗口调用的Activity 返回一个值_popupwindow_开发99编程知识库...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。