下面列出了怎么用android.widget.BaseAdapter的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
BaseAdapter adapter = (BaseAdapter)parent.getAdapter();
String emotion = (String)adapter.getItem(position);
if (StringUtil.isEmpty(emotion)) {
return;
}
EditText etText = (EditText)((Activity)context).findViewById(R.id.etText);
int currentPos = 0;
if (etText != null) {
currentPos = etText.getSelectionStart();
etText.getText().insert(currentPos, emotion);
}
}
/**
* Sets underlying adapter with your data collection.
* If you want to inject your implementation of {@link AdmobAdapterCalculator} please set it before this call
*/
public Builder setAdapter(BaseAdapter adapter) {
mAdapter = adapter;
mAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
notifyDataSetChanged();
}
@Override
public void onInvalidated() {
notifyDataSetInvalidated();
}
});
return this;
}
/**
* Sets underlying adapter with your data collection.
* If you want to inject your implementation of {@link AdmobAdapterCalculator} please set it before this call
*/
public Builder setAdapter(BaseAdapter adapter) {
mAdapter = adapter;
mAdapter.registerDataSetObserver(new DataSetObserver() {
@Override
public void onChanged() {
notifyDataSetChanged();
}
@Override
public void onInvalidated() {
notifyDataSetInvalidated();
}
});
return this;
}
/**
* Binds this adapter to the given {@link AdapterView}, setting it as its adapter. This should be done by
* construction or immediately after, before this adapter is used. This mechanism sets this class as the view's
* adapter and permits certain functionality such as click events. Without it, this class will still function as
* a normal {@link BaseAdapter}, but additional functionality may not work. Ignore this step at your own risk.
*
* @param adapterView The {@link AdapterView} to bind to.
*/
public void bindToAdapterView(AdapterView<? super BaseAdapter> adapterView) {
if (adapterView != null) {
adapterView.setAdapter(this);
// Spinners don't like on item click listeners.
// We will still delegate calls to it since you're clicking on an item to select it...
if (!(adapterView instanceof Spinner)) {
adapterView.setOnItemClickListener(internalItemClickListener);
} else {
adapterView.setOnItemSelectedListener(internalItemSelectedListener);
}
adapterView.setOnItemLongClickListener(internalLongClickListener);
}
}
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (AppConfig.INSTANCE.getBoolean(view.getContext(), AppConfig.Key.SCROLLING_PAUSE_LOAD) && view.getAdapter() != null) {
ListAdapter listAdapter = view.getAdapter();
if (listAdapter instanceof WrapperListAdapter) {
listAdapter = ((WrapperListAdapter) listAdapter).getWrappedAdapter();
}
if (listAdapter instanceof BaseAdapter) {
if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL) {
if (!sketch.getConfiguration().isPauseLoadEnabled()) {
sketch.getConfiguration().setPauseLoadEnabled(true);
}
} else if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) {
if (sketch.getConfiguration().isPauseLoadEnabled()) {
sketch.getConfiguration().setPauseLoadEnabled(false);
((BaseAdapter) listAdapter).notifyDataSetChanged();
}
}
}
}
if (absListScrollListener != null) {
absListScrollListener.onScrollStateChanged(view, scrollState);
}
}
/**
* if working in {@link android.widget.AdapterView}, we should response
* {@link android.widget.Adapter} isEnable(int position).
*
* @return true when item is enabled, else disabled.
*/
private boolean isEnabledInAdapterView() {
@SuppressWarnings("rawtypes")
AdapterView adapterView = getAdapterView();
boolean enable = true;
if (adapterView != null) {
Adapter adapter = adapterView.getAdapter();
if (adapter != null) {
int p = adapterView.getPositionForView(ZSwipeItem.this);
if (adapter instanceof BaseAdapter) {
enable = ((BaseAdapter) adapter).isEnabled(p);
} else if (adapter instanceof ListAdapter) {
enable = ((ListAdapter) adapter).isEnabled(p);
}
}
}
return enable;
}
private void refreshT9SearchGv() {
if (null == mT9SearchGv) {
return;
}
BaseAdapter baseAdapter = (BaseAdapter) mT9SearchGv.getAdapter();
Log.i(TAG, "getCount"+baseAdapter.getCount()+"");
if (null != baseAdapter) {
baseAdapter.notifyDataSetChanged();
if (baseAdapter.getCount() > 0) {
ViewUtil.showView(mT9SearchGv);
ViewUtil.hideView(mSearchResultPromptTv);
} else {
ViewUtil.hideView(mT9SearchGv);
ViewUtil.showView(mSearchResultPromptTv);
}
}
}
public void setAdapter(BaseAdapter adapter) {
super.setAdapter(adapter);
mAdapter = (IRefreshAndEditableAdapter) adapter;
setEditable(isEditable);
if (autoRefresh) {
refresh();
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.emotion_gird, container, false);
BaseAdapter adapter = new XiHaHouEmojiAdapter(mContext);
GridView grid = (GridView) view.findViewById(R.id.grid);
grid.setAdapter(adapter);
grid.setOnItemClickListener(GlobalOnItemClickManager.getInstance().getOnItemClickListener(1));
return view;
}
public static void doFavorite(final Activity activity, final Status s,
final BaseAdapter adapter) {
final ActionResultHandler li = new ActionResultHandler() {
@Override
public void onActionSuccess(final int type, final String message) {
if (type == Constants.TYPE_FAVORITES_CREATE) {
s.favorited = true;
} else {
s.favorited = false;
}
adapter.notifyDataSetChanged();
}
};
FanfouServiceManager.doFavorite(activity, s, li);
}
/**
*
* @param message
* @param v
* @param iv_read_status
* @param context
* @param activity
* @param user
* @param chatType
*/
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
String username) {
this.message = message;
voiceBody = (VoiceMessageBody) message.getBody();
this.iv_read_status = iv_read_status;
this.adapter = adapter;
voiceIconView = v;
this.activity = activity;
this.chatType = message.getChatType();
}
public NavBean(@TYPE int type, BaseAdapter adapter) {
this.type = type;
this.adapter = adapter;
switch (type) {
case TYPE_REPOST:
title = "转发";
break;
case TYPE_COMMENT:
title = "评论";
break;
case TYPE_LIKE:
title = "赞";
break;
}
}
/**
* Create a new {@link com.marshalchen.common.uimodule.listviewanimations.itemmanipulation.AnimateAdditionAdapter} with given {@link android.widget.BaseAdapter}.
*
* @param baseAdapter should implement {@link com.marshalchen.common.uimodule.listviewanimations.itemmanipulation.AnimateAdditionAdapter.Insertable},
* or be a {@link com.marshalchen.common.uimodule.listviewanimations.BaseAdapterDecorator} whose BaseAdapter implements the interface.
*/
public AnimateAdditionAdapter(final BaseAdapter baseAdapter) {
super(baseAdapter);
BaseAdapter rootAdapter = getRootAdapter();
if (!(rootAdapter instanceof Insertable)) {
throw new IllegalArgumentException("BaseAdapter should implement Insertable!");
}
mInsertable = (Insertable<T>) rootAdapter;
mInsertQueue = new InsertQueue<T>(mInsertable);
}
public BaseAdapter loadProjectMetaEditor(Context context, Document doc) {
String title = doc.getElementsByTagName(ComprehensionMetaModel.TITLE_TAG).item(0).getTextContent();
String passage = doc.getElementsByTagName(ComprehensionMetaModel.PASSAGE_TAG).item(0).getTextContent();
long timer = Long.parseLong(doc.getElementsByTagName(ComprehensionMetaModel.TIMER_TAG).item(0).getTextContent());
metaData.add(new ComprehensionMetaModel(title, passage, timer));
metaAdapter = new ComprehensionMetaAdapter(context, metaData);
setEmptyView((Activity) context);
return metaAdapter;
}
/**
* 返回纵向表头的适配器
*
* @return adapter of column ListView
*/
private BaseAdapter getColumnAdapter() {
if (columnAdapter == null) {
columnAdapter = new ColumnAdapter(context, android.R.layout.simple_list_item_1, getColumnDataList());
}
return columnAdapter;
}
public void copySelectedNotes(SparseBooleanArray checkedIndices, BaseAdapter notesAdapter, String destination) {
for (int i = 0; i < checkedIndices.size(); i++) {
if (checkedIndices.valueAt(i)) {
File file = (File) notesAdapter.getItem(checkedIndices.keyAt(i));
copyFile(file, destination);
}
}
}
public EaseChatRow(Context context, EMMessage message, int position, BaseAdapter adapter) {
super(context);
this.context = context;
this.activity = (Activity) context;
this.message = message;
this.position = position;
this.adapter = adapter;
inflater = LayoutInflater.from(context);
initView();
}
/**
*
* @param message
* @param v
* @param iv_read_status
* @param context
* @param activity
* @param user
* @param chatType
*/
public VoicePlayClickListener(EMMessage message, ImageView v, ImageView iv_read_status, BaseAdapter adapter, Activity activity,
String username) {
this.message = message;
voiceBody = (VoiceMessageBody) message.getBody();
this.iv_read_status = iv_read_status;
this.adapter = adapter;
voiceIconView = v;
this.activity = activity;
this.chatType = message.getChatType();
}
public void setAdapter(BaseAdapter adapter){
if (mAdapter == null){
mAdapter = adapter;
if (mObserver == null){
mObserver = new DataChangeObserver();
mAdapter.registerDataSetObserver(mObserver);
}
drawLayout();
}
}
private void adjustAutoscanPrefs() {
PreferenceScreen autoScanScreen =
(PreferenceScreen) findPreference(R.string.pref_category_auto_scan_key);
PreferenceCategory movementAndSelectionCategory = getMovementAndSelectionCategory();
Preference autoScanKeyPreference =
movementAndSelectionCategory.findPreference(
getString(R.string.pref_key_mapped_to_auto_scan_key));
Preference reverseAutoScanKeyPreference =
movementAndSelectionCategory.findPreference(
getString(R.string.pref_key_mapped_to_reverse_auto_scan_key));
boolean isAutoScanEnabled = SwitchAccessPreferenceUtils.isAutoScanEnabled(getActivity());
if (isAutoScanEnabled) {
autoScanScreen.setSummary(R.string.preference_on);
autoScanKeyPreference.setTitle(R.string.title_pref_category_auto_scan);
reverseAutoScanKeyPreference.setTitle(R.string.action_name_reverse_auto_scan);
if (FeatureFlags.groupSelectionWithAutoScan()) {
return;
}
if (SwitchAccessPreferenceUtils.isGroupSelectionEnabled(getActivity())) {
/* If somehow both autoscan and group selection are enabled, turn off group selection. */
SwitchAccessPreferenceUtils.setScanningMethod(
getActivity(), R.string.row_col_scanning_key);
}
} else {
autoScanScreen.setSummary(R.string.preference_off);
autoScanKeyPreference.setTitle(R.string.title_pref_auto_scan_disabled);
reverseAutoScanKeyPreference.setTitle(R.string.title_pref_reverse_auto_scan_disabled);
if (SwitchAccessPreferenceUtils.isGroupSelectionEnabled(getActivity())
&& !FeatureFlags.groupSelectionWithAutoScan()) {
findPreference(R.string.pref_category_auto_scan_key).setEnabled(false);
}
}
((BaseAdapter) autoScanScreen.getRootAdapter()).notifyDataSetChanged();
ScanningMethodPreference scanMethodsPref = getScanningMethodPreference();
scanMethodsPref.enableScanningMethod(R.string.group_selection_key, !isAutoScanEnabled);
}
private void invalidate() {
if (mGrid.getAdapter() == null) {
mGrid.setAdapter(new ColorGridAdapter());
mGrid.setSelector(
ResourcesCompat.getDrawable(getResources(), R.drawable.md_transparent, null));
} else {
((BaseAdapter) mGrid.getAdapter()).notifyDataSetChanged();
}
if (getDialog() != null) {
getDialog().setTitle(getTitle());
}
}
@Override
public void onLoadAppInfoList(BaseAdapter adapter) {
Log.d("MainApp", "加载数据咯");
app_listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
public ListContextMenuListener(Context context, BaseAdapter adapter, int fileType) {
mContext = context;
mAdapter = adapter;
mFileType = fileType;
mCallBack = null;
mResideMenu = null;
}
public EaseChatRow(Context context, EMMessage message, int position, BaseAdapter adapter) {
super(context);
this.context = context;
this.activity = (Activity) context;
this.message = message;
this.position = position;
this.adapter = adapter;
inflater = LayoutInflater.from(context);
initView();
}
/**
* 主要更新一下刷新时间啦!
* @param adapter
* @date 2013-11-20 下午5:35:51
* @change JohnWatson
* @version 1.0
*/
public void setAdapter(BaseAdapter adapter) {
// 最近更新: Time
mLastUpdatedTextView.setText(
getResources().getString(R.string.p2refresh_refresh_lasttime) +
new SimpleDateFormat(DATE_FORMAT_STR, Locale.CHINA).format(new Date()));
super.setAdapter(adapter);
}
public View getDropDownView(int position, View convertView, ViewGroup parent) {
return ((BaseAdapter) this.mDelegate).getDropDownView(position, convertView, parent);
}
public void notifyDataSetInvalidated() {
((BaseAdapter) this.mDelegate).notifyDataSetInvalidated();
}
@Override
public BaseAdapter currentTemplateEditorAdapter() {
return adapter;
}
public AnimatedContactAdapter(BaseAdapter baseAdapter, float scaleFrom)
{
super(baseAdapter, scaleFrom);
}
public ScaleInAnimationAdapter(final BaseAdapter baseAdapter, final float scaleFrom) {
this(baseAdapter, scaleFrom, DEFAULTANIMATIONDELAYMILLIS, DEFAULTANIMATIONDURATIONMILLIS);
}