use of android.widget.AdapterView 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.AdapterView in project coursera-android by aporter.
the class AutoCompleteActivity method onCreate.
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Get a reference to the AutoCompleteTextView
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
// Create an ArrayAdapter containing country names
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
// Set the adapter for the AutoCompleteTextView
textView.setAdapter(adapter);
textView.setOnItemClickListener(new OnItemClickListener() {
// Display a Toast Message when the user clicks on an item in the AutoCompleteTextView
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Toast.makeText(getApplicationContext(), "The winner is:" + arg0.getAdapter().getItem(arg2), Toast.LENGTH_SHORT).show();
}
});
}
use of android.widget.AdapterView in project coursera-android by aporter.
the class GalleryActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery g = (Gallery) findViewById(R.id.gallery);
// Create a new ImageAdapter and set in as the Adapter for the Gallery
g.setAdapter(new ImageAdapter(this));
// Set an setOnItemClickListener on the Gallery
g.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
// Display a Toast message indicate the selected item
Toast.makeText(GalleryActivity.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
use of android.widget.AdapterView in project coursera-android by aporter.
the class GridLayoutActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
GridView gridview = (GridView) findViewById(R.id.gridview);
// Create a new ImageAdapter and set it as the Adapter for this GridView
gridview.setAdapter(new ImageAdapter(this, mThumbIdsFlowers));
// Set an setOnItemClickListener on the GridView
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
//Create an Intent to start the ImageViewActivity
Intent intent = new Intent(GridLayoutActivity.this, ImageViewActivity.class);
// Add the ID of the thumbnail to display as an Intent Extra
intent.putExtra(EXTRA_RES_ID, (int) id);
// Start the ImageViewActivity
startActivity(intent);
}
});
}
use of android.widget.AdapterView 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();
}
});
}
Aggregations