Search in sources :

Example 71 with ListView

use of android.widget.ListView in project AndroidSDK-RecipeBook by gabu.

the class Recipe040 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // 文字列のみのシンプルなAdapterを作成
    ArrayAdapter<String> adapter;
    adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    // 0から19までのリストアイテムを追加
    for (int i = 0; i < 20; i++) {
        adapter.add("item_" + i);
    }
    ListView listView = (ListView) findViewById(R.id.ListView01);
    listView.setAdapter(adapter);
    // 表示位置を指定
    listView.setSelection(10);
}
Also used : ListView(android.widget.ListView)

Example 72 with ListView

use of android.widget.ListView in project AndroidSDK-RecipeBook by gabu.

the class Recipe041 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    // アイコン画像を生成
    Bitmap defaultImage;
    defaultImage = BitmapFactory.decodeResource(getResources(), R.drawable.default_image);
    // テストデータを作成
    List<ListItem> list = new ArrayList<ListItem>();
    ListItem item1 = new ListItem();
    item1.image = defaultImage;
    item1.name = "gabu";
    item1.comment = "検索なら http://google.com/ がオススメ。";
    list.add(item1);
    ListItem item2 = new ListItem();
    item2.image = defaultImage;
    item2.name = "gabu";
    item2.comment = "連絡先は tsukada.shouya@gmail.com です!";
    list.add(item2);
    ListItem item3 = new ListItem();
    item3.image = defaultImage;
    item3.name = "gabu";
    item3.comment = "電話 090-9999-9999";
    list.add(item3);
    ListItem item4 = new ListItem();
    item4.image = defaultImage;
    item4.name = "gabu";
    item4.comment = "Address: 620 Eighth Avenue New York, NY 10018";
    list.add(item4);
    ListItem item5 = new ListItem();
    item5.image = defaultImage;
    item5.name = "gabu";
    item5.comment = "日本表記だと?住所: 〒460-0031 愛知県名古屋市中区本丸1−1";
    list.add(item5);
    // ListItemAdapterを生成
    ListItemAdapter adapter;
    adapter = new ListItemAdapter(this, 0, list);
    // ListViewにListItemAdapterをセット
    ListView listView = (ListView) findViewById(R.id.ListView01);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ListView listView = (ListView) parent;
            //                ListItem item = (ListItem)listView.getSelectedItem(); // itemがnull
            ListItem item = (ListItem) listView.getItemAtPosition(position);
            Log.d(TAG, "選択されたアイテムのcomment=" + item.comment);
            TextView textView = (TextView) view.findViewById(R.id.name);
            Log.d(TAG, "選択されたViewのTextView(name)のtext=" + textView.getText());
        }
    });
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "onItemLongClick position=" + position);
            // ちなみに、falseを返すとイベントが継続するのでonItemClickも呼び出されます。
            return true;
        }
    });
}
Also used : ArrayList(java.util.ArrayList) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) Bitmap(android.graphics.Bitmap) ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView)

Example 73 with ListView

use of android.widget.ListView in project AndroidSDK-RecipeBook by gabu.

the class Recipe046 method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1);
    // リストアイテムを追加
    for (int i = 0; i < 20; i++) {
        mAdapter.add("item_" + i);
    }
    // ListViewを取得
    ListView listView = (ListView) findViewById(R.id.ListView01);
    // ListViewにフッターを追加
    // 必ずsetAdapterの前に呼び出すこと
    listView.addFooterView(getLayoutInflater().inflate(R.layout.footer, null), null, true);
    // ListViewにAdapterを追加
    listView.setAdapter(mAdapter);
    // リスナーをセット
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // クリックされたViewがフッターか判定
            if (view.getId() == R.id.Footer) {
                // 表示する数字を計算
                int count = mAdapter.getCount();
                int max = count + 5;
                for (; count < max; count++) {
                    // リストアイテムを追加
                    mAdapter.add("item_" + count);
                }
            }
        }
    });
}
Also used : ListView(android.widget.ListView) AdapterView(android.widget.AdapterView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 74 with ListView

use of android.widget.ListView in project coursera-android by aporter.

the class ListViewActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Create a new Adapter containing a list of colors
    // Set the adapter on this ListActivity's built-in ListView
    setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, getResources().getStringArray(R.array.colors)));
    ListView lv = getListView();
    // Enable filtering when the user types in the virtual keyboard
    lv.setTextFilterEnabled(true);
    // Set an setOnItemClickListener on the ListView
    lv.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // Display a Toast message indicting the selected item
            Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : ListView(android.widget.ListView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 75 with ListView

use of android.widget.ListView in project quickstart-android by firebase.

the class ChooserActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chooser);
    // Set up ListView and Adapter
    ListView listView = (ListView) findViewById(R.id.list_view);
    MyArrayAdapter adapter = new MyArrayAdapter(this, android.R.layout.simple_list_item_2, CLASSES);
    adapter.setDescriptionIds(DESCRIPTION_IDS);
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
}
Also used : ListView(android.widget.ListView)

Aggregations

ListView (android.widget.ListView)1139 View (android.view.View)739 AdapterView (android.widget.AdapterView)444 TextView (android.widget.TextView)389 ImageView (android.widget.ImageView)167 Intent (android.content.Intent)148 AbsListView (android.widget.AbsListView)135 OnItemClickListener (android.widget.AdapterView.OnItemClickListener)97 ArrayAdapter (android.widget.ArrayAdapter)97 ArrayList (java.util.ArrayList)81 ViewGroup (android.view.ViewGroup)75 ListAdapter (android.widget.ListAdapter)71 OnClickListener (android.view.View.OnClickListener)65 LayoutInflater (android.view.LayoutInflater)63 Bundle (android.os.Bundle)57 Button (android.widget.Button)55 LinearLayout (android.widget.LinearLayout)50 SuppressLint (android.annotation.SuppressLint)34 DialogInterface (android.content.DialogInterface)34 ScrollView (android.widget.ScrollView)31