0

我在意图的帮助下传递行 ID。调用方法是自定义适配器 -

holder.text.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "TEXT CLICKED" + pos , Toast.LENGTH_SHORT).show();
                Intent intent = new Intent(context,ReminderModificationActivity.class);
                long longPos = (long)pos;
                intent.putExtra(TasksDBAdapter.KEY_ROWID, pos);
                Log.i(TAG, "row clickd --> " + longPos);
                ((Activity) context).startActivityForResult(intent, ACTIVITY_EDIT);
            }
        });

OnCreate()ReminderModificationActivity 方法尝试检索数据。代码 -

protected void onCreate(Bundle savedInstanceState){
        dbHelper = new TasksDBAdapter(this);

        //set current theme
        settingsDBAdapter = new SettingsDBAdapter(this);
        settingsDBAdapter.open();

        setSettingsTheme();
        setContentView(R.layout.reminder_modify);
        mCalendar =  Calendar.getInstance();

        Log.i(getLocalClassName(), "VALUE of Button--->" + findViewById(R.id.SetDateButtonId));
        mDateButton = (Button) findViewById(R.id.SetDateButtonId);
        mTimeButton = (Button) findViewById(R.id.SetTimeButtonId);
        mConfirmButton = (Button) findViewById(R.id.SaveButtonId);
        mTitleText = (EditText) findViewById(R.id.TitleEditTextId);
        mBodyText = (EditText) findViewById(R.id.DescriptionEditTextId);

        mRowId = savedInstanceState != null ? savedInstanceState.getLong(TasksDBAdapter.KEY_ROWID) : null ;
        registerButtonListenersAndSetDefaultText();
        Log.i(TAG, "getIntent-->" + getIntent() + mRowId);
        //code to check what row id have been passed
        if(getIntent() != null) { 
            ---->>>MAIN CODE
            Log.i(TAG, "mRowId in getintent-->" +  mRowId + "row id passed-->" +  getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1));
            mRowId =  getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1);
            // Do stuff with the row id here
            if(mRowId != -1){
                //code if RowId valid

            }
        }

        super.onCreate(savedInstanceState);
        Log.i(TAG, "mROwId in onCreate ReminderNotification again-->" + mRowId);    
    }

标记为 MAIN CODE 的行捕获意图数据,但 Log.i 给出的值

getIntent().getLongExtra(TasksDBAdapter.KEY_ROWID, -1))

作为-1。可以 sumone 请帮我解决这个问题。提前谢谢,雷

4

1 回答 1

0

看到你投射poslongPos,你应该longPos在你的意图中额外使用,但你使用pos.

如果您要将代码更改为:

        Intent intent = new Intent(context,ReminderModificationActivity.class);
        long longPos = (long)pos;
        intent.putExtra(TasksDBAdapter.KEY_ROWID, longPos); //<< changed to longPos

它应该工作

于 2012-11-15T19:12:20.257 回答