0

我目前难以将复选框中的名称从一项活动传递到另一项活动。实际上,名称应在检查后插入到我的数据库表中,然后将其传递给前面提到的活动。有人对这样做有任何想法吗?提供的任何帮助将不胜感激。

作为参考,我的项目的代码。

  BuddyDBAdapter buddyDB = new BuddyDBAdapter(this);

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.contacts_list);

        ListView list = (ListView) findViewById(android.R.id.list);
        //ListView list = getListView();
        list.setOnItemClickListener(new OnItemClickListener()
        {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                    long id)
            {

               Cursor cursor = null;

               cursor = (Cursor) parent.getItemAtPosition(position);
               Intent intent = new Intent(ContactsList.this, Create_Events.class);
               intent.putExtra("name", cursor.getString(cursor.getColumnIndex(buddyDB.KEY_NAME)));
               startActivity(intent);

            }

        });

        Uri allContacts = Uri.parse("content://contacts/people");

        Cursor c = managedQuery(allContacts, null, null, null, null);

        String[] columns = new String[] {ContactsContract.Contacts.DISPLAY_NAME};
        int[] views = new int[]  {R.id.contactCheckbox};

        startManagingCursor(c);

        SimpleCursorAdapter friendsAdapter = new SimpleCursorAdapter(this, R.layout.contacts_list, c, columns, views);
        this.setListAdapter(friendsAdapter);



    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id)
    {
        buddyDB.open();
        //long name_id;
        super.onListItemClick(l, v, position, id);

        Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor();
        c.moveToPosition(position);

        /*TextView contactName = (TextView) v.findViewById(R.id.contactName);
        String NameValue = contactName.getText().toString();

        name_id = buddyDB.insertNames(NameValue);


        Toast.makeText(getBaseContext(),
                "Selected: " + buddiesList[position], Toast.LENGTH_SHORT).show();       
        buddyDB.close();*/


            nameCheck = (CheckBox) v.findViewById(R.id.contactCheckbox);
            nameCheck.setOnCheckedChangeListener(new OnCheckedChangeListener()
                {               
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView,
                            boolean isChecked)
                    {
                        long name_id;
                        String NameValue = nameCheck.getText().toString();
                        name_id = buddyDB.insertNames(NameValue);
                        /*if(isChecked)
                        {
                            nameCheck = 1;
                        }else
                        {
                            nameCheck = 0;
                        }*/                 
                    }                   
                });     
            buddyDB.close();        
    }

}

同样,任何人的任何帮助都将不胜感激。非常感谢!

4

2 回答 2

0

在要将参数传递给另一个活动的地方使用此代码。

Intent n = new Intent(actA.this , actB.class);
n.putExtra("name", NameValue);
startActivity(n);
于 2012-09-11T09:01:36.407 回答
0

这可能会帮助你

从 oneActivity 传递名称值

Intent n = new Intent(actA.this , actB.class);
n.putExtra("name", NameValue);
startActivity(n);

获取给定的值

Intent igetlist = getIntent();
String singleid = igetlist.getExtras().getString("name");
于 2012-09-11T09:21:50.840 回答