use of android.widget.ListView in project Android-AccountChooser by frakbot.
the class ChooseAccountTypeActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "ChooseAccountTypeActivity.onCreate(savedInstanceState=" + savedInstanceState + ")");
}
// Read the validAccountTypes, if present, and add them to the setOfAllowableAccountTypes
Set<String> setOfAllowableAccountTypes = null;
String[] validAccountTypes = getIntent().getStringArrayExtra(ChooseTypeAndAccountActivity.EXTRA_ALLOWABLE_ACCOUNT_TYPES_STRING_ARRAY);
if (validAccountTypes != null) {
setOfAllowableAccountTypes = new HashSet<String>(validAccountTypes.length);
for (String type : validAccountTypes) {
setOfAllowableAccountTypes.add(type);
}
}
// create a map of account authenticators
buildTypeToAuthDescriptionMap();
// Create a list of authenticators that are allowable. Filter out those that
// don't match the allowable account types, if provided.
mAuthenticatorInfosToDisplay = new ArrayList<AuthInfo>(mTypeToAuthenticatorInfo.size());
for (Map.Entry<String, AuthInfo> entry : mTypeToAuthenticatorInfo.entrySet()) {
final String type = entry.getKey();
final AuthInfo info = entry.getValue();
if (setOfAllowableAccountTypes != null && !setOfAllowableAccountTypes.contains(type)) {
continue;
}
mAuthenticatorInfosToDisplay.add(info);
}
if (mAuthenticatorInfosToDisplay.isEmpty()) {
Bundle bundle = new Bundle();
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "no allowable account types");
setResult(Activity.RESULT_OK, new Intent().putExtras(bundle));
finish();
return;
}
if (mAuthenticatorInfosToDisplay.size() == 1) {
setResultAndFinish(mAuthenticatorInfosToDisplay.get(0).desc.type);
return;
}
setContentView(R.layout.choose_account_type);
// Setup the list
ListView list = (ListView) findViewById(android.R.id.list);
// Use an existing ListAdapter that will map an array of strings to TextViews
list.setAdapter(new AccountArrayAdapter(this, android.R.layout.simple_list_item_1, mAuthenticatorInfosToDisplay));
list.setChoiceMode(ListView.CHOICE_MODE_NONE);
list.setTextFilterEnabled(false);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
setResultAndFinish(mAuthenticatorInfosToDisplay.get(position).desc.type);
}
});
}
use of android.widget.ListView in project Android-AccountChooser by frakbot.
the class ChooseTypeAndAccountActivity method populateUIAccountList.
/**
* Populates the UI ListView with the given list of items and selects an item
* based on {@code mSelectedItemIndex} member variable.
*/
private final void populateUIAccountList(String[] listItems) {
ListView list = (ListView) findViewById(android.R.id.list);
list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, listItems));
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setItemsCanFocus(false);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
mSelectedItemIndex = position;
mOkButton.setEnabled(true);
}
});
if (mSelectedItemIndex != SELECTED_ITEM_NONE) {
list.setItemChecked(mSelectedItemIndex, true);
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, "List item " + mSelectedItemIndex + " should be selected");
}
}
}
use of android.widget.ListView in project AndroidSDK-RecipeBook by gabu.
the class Recipe093 method onCreate.
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// 外部ストレージにある音楽データのUri
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
// 取得するカラム(今回は無指定=すべて)
String[] projection = null;
// 検索条件
String selection = null;
// 検索条件の値
String[] selectionArgs = null;
// ソート条件
String sortOrder = null;
// 検索結果をCursorで取得しつつ、
// カーソルの管理をアクティビティに任せる
Cursor cursor = managedQuery(uri, projection, selection, selectionArgs, sortOrder);
for (String column : cursor.getColumnNames()) {
Log.d(TAG, column);
}
// ListViewに表示するカラム名の配列
String[] from = { // タイトル
MediaStore.Audio.AudioColumns.TITLE, // アーティスト名
MediaStore.Audio.AudioColumns.ARTIST, // 曲の長さ
MediaStore.Audio.AudioColumns.DURATION };
// fromに対応するビューのリソースID
int[] to = { R.id.title, R.id.artist, R.id.duration };
// SimpleCursorAdapterを生成
SimpleCursorAdapter adapter;
adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.row, cursor, from, to);
// Viewにセットする値を加工するためViewBinderをセット
adapter.setViewBinder(new AudioListViewBinder());
// ListViewにAdapterをセット
ListView listView = (ListView) findViewById(R.id.list_view);
listView.setAdapter(adapter);
}
use of android.widget.ListView in project KenBurnsView by flavioarfaria.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.main_options, android.R.layout.simple_list_item_1);
final ListView listView = (ListView) findViewById(android.R.id.list);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
onListItemClick(parent, view, position, id);
}
});
}
use of android.widget.ListView in project XobotOS by xamarin.
the class ListFragment method ensureList.
private void ensureList() {
if (mList != null) {
return;
}
View root = getView();
if (root == null) {
throw new IllegalStateException("Content view not yet created");
}
if (root instanceof ListView) {
mList = (ListView) root;
} else {
mStandardEmptyView = (TextView) root.findViewById(com.android.internal.R.id.internalEmpty);
if (mStandardEmptyView == null) {
mEmptyView = root.findViewById(android.R.id.empty);
} else {
mStandardEmptyView.setVisibility(View.GONE);
}
mProgressContainer = root.findViewById(com.android.internal.R.id.progressContainer);
mListContainer = root.findViewById(com.android.internal.R.id.listContainer);
View rawListView = root.findViewById(android.R.id.list);
if (!(rawListView instanceof ListView)) {
throw new RuntimeException("Content has view with id attribute 'android.R.id.list' " + "that is not a ListView class");
}
mList = (ListView) rawListView;
if (mList == null) {
throw new RuntimeException("Your content must have a ListView whose id attribute is " + "'android.R.id.list'");
}
if (mEmptyView != null) {
mList.setEmptyView(mEmptyView);
} else if (mEmptyText != null) {
mStandardEmptyView.setText(mEmptyText);
mList.setEmptyView(mStandardEmptyView);
}
}
mListShown = true;
mList.setOnItemClickListener(mOnClickListener);
if (mAdapter != null) {
ListAdapter adapter = mAdapter;
mAdapter = null;
setListAdapter(adapter);
} else {
// have our data right away and start with the progress indicator.
if (mProgressContainer != null) {
setListShown(false, false);
}
}
mHandler.post(mRequestFocus);
}
Aggregations