2011-05-13 110 views
0

我知道什么是必须做..这是我必须做的..机器人编程

创建自定义列表视图(在左侧的列表行的复选框)在您的应用程序,与适配器获得数据一个从您的应用程序从联系人应用程序使用服务或线程,然后膨胀它的视图

但我遇到了麻烦...... 我knw的基础太..然后通过arraylist在适配器...

如果任何机构可以帮助我..我在这一周卡住了...我想要得到它...

ArrayList<WhateverTypeYouWant> mArrayList = new ArrayList<WhateverTypeYouWant>(); 
for(mCursor.moveToFirst(); mCursor.moveToNext(); mCursor.isAfterLast()) { 
    // The Cursor is now set to the right position 
    mArrayList.add(mCursor.getWhateverTypeYouWant(WHATEVER_COLUMN_INDEX_YOU_WANT)); 
} 

这里是代码...

package com.exiom.productcatalogue; 

import java.util.ArrayList; 
import java.util.HashMap; 

import android.app.Activity; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.provider.ContactsContract; 
import android.util.SparseBooleanArray; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.ArrayAdapter; 
import android.widget.Button; 
import android.widget.ListView; 
import android.widget.SimpleAdapter; 
import android.widget.Toast; 

public class WebexAttendeeList extends Activity { 

ListView lstAttends; 
ListView lstContacts; 
private ArrayList<String> aAttendees = new ArrayList<String>(); 
private ArrayList<String> aContacts= new ArrayList<String>(); 

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

//  lstContacts = (ListView)findViewById(R.id.lstContacts); 
     lstAttends = (ListView)findViewById(R.id.lstAttendees); 

     Cursor cur = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); 

     ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>(); 
     HashMap<String, String> sContact = new HashMap<String, String>(); 

    if (cur.getCount() > 0) { 
     while (cur.moveToNext()) { 
      String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID)); 
      String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); 
      sContact = new HashMap<String, String>(); 
    Cursor emailCur = getContentResolver().query( 
     ContactsContract.CommonDataKinds.Email.CONTENT_URI, 
     null, 
     ContactsContract.CommonDataKinds.Email.CONTACT_ID + " = ?", 
     new String[]{id}, null); 
    while (emailCur.moveToNext()) { 
     // This would allow you get several email addresses 
      // if the email addresses were stored in an array 
     String email = emailCur.getString(
          emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA)); 
//   String emailType = emailCur.getString(
//       emailCur.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); 
     sContact.put("name", name); 
     sContact.put("email", email); 
     mylist.add(sContact); 
     aAttendees.add(name); 
     } 
     emailCur.close(); 

     } 
     cur.close(); 
    } 

// SimpleAdapter mAttendees = new SimpleAdapter(this, mylist, R.layout.multicolumnlayout, 
//   new String[] {"name", "email"}, new int[] {R.id.NAME, R.id.EMAIL}); 
//  lstContacts.setAdapter(mAttendees); 
//  lstContacts.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 
    ArrayAdapter<String> attendAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_multiple_choice, aAttendees); 
    lstAttends.setAdapter(attendAdapter); 
     lstAttends.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); 

    Button btnStart = (Button)this.findViewById(R.id.btnStartWebex); 
    btnStart.setOnClickListener(mStartButtonListener); 
    Button btnCancel = (Button)this.findViewById(R.id.btnWebexCancel); 
     btnCancel.setOnClickListener(mCancelButtonListener); 
//  lstContacts.setOnClickListener(mSelectAttendee); 

    } 

    public void StartWebEx() 
    { 
//  WebexClient webex = null ; 
//  String webExId = ""; 
// String backUrl = ""; 
// 
// webex.getLoginUrl(webExId, backUrl); 

    int len = lstAttends.getCount(); 
    SparseBooleanArray checked = lstAttends.getCheckedItemPositions(); 
    for (int i = 0; i < len; i++) 
     if (checked.get(i)) { 
     String item = aAttendees.get(i).toString(); 
     /* do whatever you want with the checked item */ 
     } 
    } 

    private OnClickListener mStartButtonListener = new OnClickListener() { 
    public void onClick(View v) { 
     // do something when the button is clicked 
     Toast.makeText(getBaseContext(), "Starting WebEx...",Toast.LENGTH_SHORT).show(); 
//  String sSQLCmd = "update U_WEBEX_SETTING set webex_url = '"+edtWURL.getText()+"', " 
//    + "webex_id = '"+edtWID.getText()+"', " 
//    + "webex_pw = '"+edtWPW.getText()+"'"; 
//  
//  db.execSQL(sSQLCmd); 
     StartWebEx(); 
     finish(); 
    }; 
    }; 

    private OnClickListener mCancelButtonListener = new OnClickListener() { 
    public void onClick(View v) { 
    // do something when the button is clicked 
    Toast.makeText(getBaseContext(), "Exiting WebEx...",Toast.LENGTH_LONG).show(); 
    finish(); 
    }; 
    }; 

    private OnClickListener mSelectAttendee = new OnClickListener() { 
     public void onClick(View v) { 
     // do something when the button is clicked 
        //  aAttendees.add(lstContacts); 
     Toast.makeText(getBaseContext(), "Selected...",Toast.LENGTH_LONG).show(); 
     finish(); 
     }; 
     }; 

} 
+0

wt u edit ..你没有做任何事情:S – tiger 2011-05-13 01:59:12

+0

你卡在哪里?我们该怎样帮助你? – Egor 2011-05-13 04:37:42

+0

我坚持在应用程序中创建一个自定义列表视图(在左边的列表行中有复选框),使用服务或线程从适配器获取数据,从联系人应用程序获取数据,然后在视图上充气当与会者按钮被点击时,我应该与复选框和两个按钮的联系人列表启动并取消..我有按钮功能..我只需要实现联系人 – tiger 2011-05-13 10:45:20

回答

0

我认为,这将有利于你。 Content Providers

+0

我已经看过这个人.. ntn是helpin – tiger 2011-05-13 10:54:07

+0

什么在本教程中对你不清楚吗? – Egor 2011-05-13 11:11:10

+0

我没有得到如何在这个 – tiger 2011-05-13 12:45:05