布尔本身重置为false时getExtra被称为 [英] Boolean resets itself to false when getExtra is called

查看:214
本文介绍了布尔本身重置为false时getExtra被称为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我调用getExtras.getBoolean(键)请将isDeleted我布尔值,它会保持自身设置为false,即使我传入true。为什么这任何有识之士正在发生?我已经尝试了很多其他的方法,但都没有成功,在保持布尔值true。

其他活动:

 公共无效deleteWorkout(查看视图)
    {
        intent.putExtra(listPosition,intent.getExtras()调用getInt(位置));
        intent.putExtra(请将isDeleted,真正的);
        的setResult(RESULT_OK,意图);
        完();
    }
 

主要活动:

 情况(列表):{
                如果(RES code == Activity.RESULT_OK)
                {
                    请将isDeleted布尔= intent.getExtras()getBoolean(请将isDeleted)。
                    INT listPosition = intent.getExtras()调用getInt(listPosition)。
                    如果(请将isDeleted)
                    {
                        adapter.remove(workoutList.get(listPosition));
                        adapter.notifyDataSetChanged();
                    }
                }
            }
            默认:
                打破;
            }
 

解决方案

有双向通/获取数据的一个活动到另一个活动。

1.新增数据的意图。

如何把:

  intent.putExtra(listPosition,intent.getExtras()调用getInt(位置));
intent.putExtra(请将isDeleted,真正的);
 

如何获得:

  INT listPosition = getIntent()getIntExtra(listPosition,0);
请将isDeleted布尔= getIntent()getBooleanExtra(请将isDeleted,假)。
 

2.添加数据捆绑,并添加束意图。

如何把:

 捆绑包=新包();
bundle.putExtra(listPosition,intent.getExtras()调用getInt(位置));
bundle.putExtra(请将isDeleted,真正的);
intent.putExtras(束)
 

如何获得:

  INT listPosition = getIntent()getExtras()调用getInt(listPosition,0)。;
请将isDeleted布尔= getIntent()getExtras()getBoolean(请将isDeleted,FALSE)。;
 

When I invoke getExtras.getBoolean(key) for my isDeleted boolean, it keeps setting itself to false, even though I'm passing in true. Any insight on why this is occurring? I've tried a lot of other methods, but haven't been successful in keeping the boolean value TRUE.

Other Activity:

   public void deleteWorkout(View view)
    {
        intent.putExtra("listPosition", intent.getExtras().getInt("position"));
        intent.putExtra("isDeleted", true);
        setResult(RESULT_OK, intent);
        finish();
    }

Main Activity:

case(List): {
                if(resCode == Activity.RESULT_OK)
                {
                    boolean isDeleted = intent.getExtras().getBoolean("isDeleted");
                    int listPosition = intent.getExtras().getInt("listPosition");
                    if(isDeleted)
                    {
                        adapter.remove(workoutList.get(listPosition));
                        adapter.notifyDataSetChanged();
                    }
                }
            }
            default:
                break;
            }

解决方案

There is two way pass/get data one activity to another activity.

1.add data to intent.

how to put :

intent.putExtra("listPosition", intent.getExtras().getInt("position"));
intent.putExtra("isDeleted", true);

how to get :

int listPosition = getIntent().getIntExtra("listPosition",0);
boolean isDeleted = getIntent().getBooleanExtra("isDeleted",false);

2.Add data to bundle and add bundle to intent.

how to put :

Bundle bundle = new Bundle();
bundle.putExtra("listPosition", intent.getExtras().getInt("position"));
bundle.putExtra("isDeleted", true);
intent.putExtras(bundle)

how to get :

int listPosition = getIntent().getExtras().getInt("listPosition",0);
boolean isDeleted = getIntent().getExtras().getBoolean("isDeleted",false);

这篇关于布尔本身重置为false时getExtra被称为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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