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);
}
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;
}
});
}
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);
}
}
}
});
}
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();
}
});
}
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);
}
Aggregations