为什么Intent在调用Activity时没有重定向?

问题描述 投票:0回答:1

我有ListView包含两个TextViews(比如说t1,t2),而ListView是由xml创建的,它在Activity中膨胀。 我的要求是,如果用户单击一个ListView项,其中包含一个新的Activity应该和当点击一个项目时,其中包含t2启动另一个Activity。 但问题是,当我点击任何ListView项目时它不起作用,它在两种情况下都移动到相同的Activity。

我的代码(作为 - 里面的getView()方法):

mylayout.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                try {
                    if (listType == 1) {
                        Log.v("active", "On Click " + (position));
                        Intent intent = new Intent(VoucherActiveScreen.this,MyVoucherDetailPage.class);
                        intent.putExtra("selectedIndex", position);
                        intent.putExtra("listType", listType);
                        startActivity(intent);
                    }
                    else if (listType == 3) {
                                 //String str = offerPrice.getText().toString();
                                 //System.out.println(str);
                                 if (voucherOffer.getIs_redeem().toString().equals("1"))
                                 {
                                    System.out.println(voucherOffer.getIs_redeem().toString()+"if Rate"); //its working when click listview which contains Rate

                                    Intent  intratedeal=new Intent(getBaseContext(),RateDeal.class);
                                    intratedeal.setClass(getBaseContext(), RateDeal.class);
                                    startActivityForResult(intratedeal, 1);
                                 }
                                 else
                                     {
                                     System.out.println(voucherOffer.getIs_redeem().toString()+"else View"); //its working when click listview which contains View
                                     Intent  intratevendor=new Intent(getBaseContext(),RateVendor.class);
                                     //intratevendor.setClass(getBaseContext(), RateVendor.class);
                                        startActivityForResult(intratevendor, 1);
                                     }
                             /*Intent intent = new Intent(
                                        VoucherActiveScreen.this,
                                        MyVoucherDetailPage.class);
                                intent.putExtra("listType", listType);
                                intent.putExtra("selectedIndex", position);*/
                                Log.v("inactiveeeeeeeeeeeeeeeeee", "On Click " + (position));

                                //startActivity(intent); 

                    }
                } catch (Exception e) {
                    // TODO: handle exception
                }
            }
        });

请任何一个帮助...控制是正确的if-else阻止但意图不重定向相同的活动

android android-intent android-listview android-activity
1个回答
0
投票

你可以在你的意图中setFlags,如下所示:

Intent intent = new Intent(VoucherActiveScreen.this,MyVoucherDetailPage.class);
intent.putExtra("selectedIndex", position);
intent.putExtra("listType", listType);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

上面的代码段将启动一项新的活动任务。看到这个链接:

http://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK

© www.soinside.com 2019 - 2024. All rights reserved.