1

Web 開発者としてのバックグラウンドを持つ私が求めているのは、非常にシンプルなはずです。Androidフォンからすべての連絡先を取得しました。

彼らの名前と番号は、連絡先 (番号 = キー) と呼ばれる HashMap にあります。私はそれらを反復処理しており、ユーザーが表示できるようにそれらのリストを作成しようとしています。キー (電話番号) はそこで利用可能である必要がありますが、表示されないようにする必要があり、リストはスクロールする必要があります。したがって、のようなもの<option value="phone">Name</option>が最適です。私は立ち往生しています。何か案は?

4

1 に答える 1

1

アダプターを使用して、リストを ListView に拡張します。

お気に入り:

public class SimpleListView extends ListActivity {

private String[] lv_arr = {};
private ListView mainListView = null;
final String SETTING_TODOLIST = "todolist";

private ArrayList<String> selectedItems = new ArrayList<String>();

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


    // Prepare an ArrayList of todo items
    ArrayList<String> listTODO = [INSERT THE VALUES FROM THE CONTACTS HERE];

    this.mainListView = getListView();

    // Bind the data with the list
    lv_arr = listTODO.toArray(new String[0]);
    mainListView.setAdapter(new ArrayAdapter<String>(SimpleListView.this,
            android.R.layout.simple_list_item_2, lv_arr));

}

}

レイアウトも必要です: simple.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="450dp" >

        <ListView
            android:id="@+id/mainListView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_above="@+id/size"
            android:layout_below="@+id/editText1"
            android:gravity="fill_vertical|fill_horizontal"
            android:horizontalSpacing="15dp"
            android:isScrollContainer="true"
            android:numColumns="1"
            android:padding="5dp"
            android:scrollbars="vertical"
            android:smoothScrollbar="true"
            android:stretchMode="columnWidth" >

</ListView>

</RelativeLayout> 
于 2012-09-13T13:51:52.667 に答える