的Andr​​oid一项活动,以弹出窗口 [英] Android one activity to to popup window

查看:122
本文介绍了的Andr​​oid一项活动,以弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是:列出所有的销售路线与放大器;亮点默认情况下,它应该是第一选择。如果销售人员选择其它选项(未选择默认值),然后弹出窗口要来。在弹出的窗口中包含的一种形式,它再跟DB.After提交弹出窗口的形式,它返回previous屏幕,它需要允许去其他位置。

My requirement is : List all sales route & highlight default, It should be first option. If the salesperson select other option(not selected default), then popup window should come. The popup window contain one form, it talk to DB.After submit the popup window form , it return previous screen , It need to allow to go other position.

请参阅我的code

这初定活动:

    ArrayList<Object> routeList = getWmRoute();
    ArrayList<String> routhPath = new ArrayList<String>();
    for(int i = 0; i<routeList.size();i++){
        routhPath.add(((WMRoute) routeList.get(i)).getDescription());
    }

    ArrayAdapter ad = new ArrayAdapter(this,android.R.layout.simple_list_item_single_choice,routhPath);
    setListAdapter(ad);
    final ListView list=getListView();
    list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    list.setItemsCanFocus(true);
    list.setTextFilterEnabled(true);
    list.setItemChecked(0,true);
    list.setSelection(0);

这是监听方法

   @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    if(position !=0 ){
        Bundle bundle = new Bundle();
        int postion = position;
        String aString = Integer.toString(postion);
        bundle.putString("positon", aString);
        Intent showContent = new Intent(getApplicationContext(),SalesRouteDevitionActivity.class);
        // startActivityForResult(showContent,0);
        startActivity(showContent);

    }
}

这是我SalesRouteDevitionActivity类

This is my SalesRouteDevitionActivity class

   array_spinner=new String[2];
    array_spinner[0]="Rain";
    array_spinner[1]="Floods";
    Bundle bundle = this.getIntent().getExtras();
    param1 = bundle.getString("param1");

    Spinner s = (Spinner) findViewById(R.id.spinner1);
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, array_spinner);
    s.setAdapter(adapter);
     final Button button = (Button) findViewById(R.id.submit);

     button.setOnClickListener(new OnClickListener() {
         public void onClick(View v) {
             Toast.makeText(SalesRouteDevitionActivity.this, "Beep Bop", Toast.LENGTH_SHORT).show();
             Intent showContent = new Intent(getApplicationContext(),SalesRouteActivity.class);

             Bundle bundle = new Bundle();
             bundle.putString("position", param1);
             Intent mIntent = new Intent();
             mIntent.putExtras(bundle);
             setResult(RESULT_OK, mIntent);
             finish();
            startActivity(showContent);


         }
     });

这是我的清单文件

  <activity android:theme="@android:style/Theme.Dialog" android:name=".SalesRouteDevitionActivity"
              android:label="Sales Route Diviation">
    </activity>

在完成弹出窗口的工作,我们如何去previous的活动,特别的地方?

After finish pop window work , how we can go to previous activity that particular place?

请帮我...

在此先感谢

推荐答案

无论你开始使用意图throught称之为startActivityForResult(your_intent,要求code)在弹出的窗口称之为

from wherever you start the popup window call it using intent throught call this startActivityForResult(your_intent,requestCode)

它将启动活动,并在弹出的活动不喜欢这种方式。

it will start the activity and in the popup activity do like this way

Bundle bundle = new Bundle();
bundle.putString("position", param1);

Intent mIntent = new Intent();
mIntent.putExtras(bundle);
setResult(RESULT_OK, mIntent);
finish();

让弹出将完成他的活动,回到previous活动在那里将其结果调用

so the popup will finish his activity and go back to previous activity where it will invoked with the result

和你的活动覆盖onActivityResult像这样

and in your activity override the onActivityResult like this way

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if(resultCode==1){
        if(resultCode==RESULT_OK)
            Toast.makeText(this, "SUCCESS", Toast.LENGTH_LONG).show();
       else
          Toast.makeText(this, "Fail", Toast.LENGTH_LONG).show();
    }
}

这篇关于的Andr​​oid一项活动,以弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆