选择联系人

时间:2013-02-08 09:56:27

标签: android android-contacts

我制作了一个应用程序,可以检索存储的所有联系人。我想创建一个应用程序,允许用户选择他想要添加到应用程序的联系人。 我应该动态创建复选框并检索所选联系人还是有其他方法可以做到这一点?

1 个答案:

答案 0 :(得分:0)

这是一个例子,就像你需要工作一样

     // MainActivity

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

   final ListView listTags = (ListView) findViewById(R.id.listPack);
   listTags.setAdapter(new ArrayAdapter<String>(this, R.layout.list_item, mStrings));
   listTags.setOnItemClickListener(new OnItemClickListener() {

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

// Toast.makeText(getParent(),“hello”,Toast.LENGTH_LONG)。show();            }        });

}


 private String[] mStrings = {

    "Comte", "Coolea", "Cooleney", "Coquetdale", "Corleggy", "Cornish Pepper",
    "Cotherstone", "Cotija", "Cottage Cheese", "Cottage Cheese (Australian)",
    "Cougar Gold", "Coulommiers", "Coverdale", "Crayeux de Roncq", "Cream Cheese",
    "Cream Havarti", "Crema Agria", "Crema Mexicana", "Creme Fraiche", "Crescenza",
    "Croghan", "Crottin de Chavignol", "Crottin du Chavignol", "Crowdie", "Crowley",
    "Cuajada", "Curd", "Cure Nantais", "Curworthy", "Cwmtawe Pecorino",
   };

// Main xml

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello" />

<ListView
    android:id="@+id/listPack"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginBottom="5dip"
    android:layout_marginLeft="5dip"
    android:layout_marginRight="5dip"
    android:layout_weight="1" >
</ListView>

    </LinearLayout>

// list_item.xml // layout