Java Code Examples for android.widget.ListAdapter

The following are top voted examples for showing how to use android.widget.ListAdapter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: adyen-android   File: PaymentMethodSelectionFragment.java   View source code 8 votes vote down vote up
private void resizeListView(ListView listView, boolean isBottomList) {
    ListAdapter adapter = listView.getAdapter();
    int count = adapter.getCount();
    int itemsHeight = 0;
    // Your views have the same layout, so all of them have
    // the same height
    View oneChild = listView.getChildAt(0);
    if (oneChild == null) {
        return;
    }
    itemsHeight = oneChild.getHeight();
    // Resize your list view
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) listView.getLayoutParams();
    params.height = isBottomList ? itemsHeight * count + itemsHeight / 2 : itemsHeight * count;
    listView.setLayoutParams(params);
}
 
Example 2
Project: Android-Kode-POS   File: MainActivity.java   View source code 6 votes vote down vote up
@Override
protected void onPostExecute(Void result) {
    super.onPostExecute(result);
    // Dismiss the progress dialog
    if (pDialog.isShowing())
        pDialog.dismiss();

    // Sorting a-z
    Collections.sort(posList, new Comparator<HashMap< String,String >>() {

        @Override
        public int compare(HashMap<String, String> lhs,
                           HashMap<String, String> rhs) {
            return lhs.get("name").compareTo(rhs.get("name"));
        }
    });

    // Updating parsed JSON data into ListView
    ListAdapter adapter = new SimpleAdapter(
            MainActivity.this, posList,
            R.layout.list_daerah, new String[]{"name"}, new int[]{R.id.name});

    lv.setAdapter(adapter);
}
 
Example 3
Project: CIA   File: ViewFollowedUsersIntentTests.java   View source code 6 votes vote down vote up
/**
 * test to make sure all followed profiles show up in the list
 */
public void testFollowingList(){

    ListAdapter adapter = ((ListView)solo.getView(R.id.vfuProfilesList)).getAdapter();

    for (Profile followed : profile.getFollowing()){

        boolean found = false;
        for (int i = 0; i < adapter.getCount(); ++i){
            if (adapter.getItem(i).equals(followed)){
                found = true;
                break;
            }
        }

        assertTrue("profile not found in followed users listview", found);
    }
}
 
Example 4
Project: CIA   File: ViewFollowedUsersIntentTests.java   View source code 6 votes vote down vote up
/**
 * test to make sure all followed profile's habit events show up in the list, and are in sorted order
 */
public void testFollowingEvents(){
    // switch to history view
    solo.clickOnView(solo.getView(R.id.vfuHistoryIcon));
    solo.sleep(600);

    ListAdapter adapter = ((ListView)solo.getView(R.id.vfuEventsList)).getAdapter();
    for (CompletedEventDisplay event : profile.getFollowedHabitHistory()){
        boolean found = false;
        for (int i = 0; i < adapter.getCount(); ++i) {
            if (adapter.getItem(i).equals(event)) {
                found = true;
                break;
            }
        }
        assertTrue("habit not found in followed user habits listview", found);
    }
}
 
Example 5
Project: NoticeDog   File: DragSortListView.java   View source code 6 votes vote down vote up
/**
 * For each DragSortListView Listener interface implemented by
 * <code>adapter</code>, this method calls the appropriate
 * set*Listener method with <code>adapter</code> as the argument.
 *
 * @param adapter The ListAdapter providing data to back
 *                DragSortListView.
 * @see ListView#setAdapter(ListAdapter)
 */
@Override
public void setAdapter(ListAdapter adapter) {
    if (adapter != null) {
        mAdapterWrapper = new AdapterWrapper(adapter);
        adapter.registerDataSetObserver(mObserver);

        if (adapter instanceof DropListener) {
            setDropListener((DropListener) adapter);
        }
        if (adapter instanceof DragListener) {
            setDragListener((DragListener) adapter);
        }
        if (adapter instanceof RemoveListener) {
            setRemoveListener((RemoveListener) adapter);
        }
    } else {
        mAdapterWrapper = null;
    }

    super.setAdapter(mAdapterWrapper);
}
 
Example 6
Project: youkes_browser   File: SuperListView.java   View source code 6 votes vote down vote up
private int measureHeight(int measureSpec) {
	int mode = MeasureSpec.getMode(measureSpec);
	if (mode == MeasureSpec.AT_MOST) {
		return MeasureSpec.makeMeasureSpec(measureSpec, mode);
	} else if (mode == MeasureSpec.EXACTLY) {
		ListAdapter adapter = getAdapter();
		if (adapter == null) {
			measureSpec = 0;
		} else {
			int result = 0;
			for (int i = 0; i < adapter.getCount(); i++) {
				View contentView = adapter.getView(i, null, null);
				contentView.measure(0, 0);
				result += contentView.getMeasuredHeight();
			}
			measureSpec = result + getDividerHeight()
					* (adapter.getCount() - 1);
		}
	}

	return MeasureSpec.makeMeasureSpec(measureSpec, mode);
}
 
Example 7
Project: pius1   File: MaterialDialog.java   View source code 6 votes vote down vote up
private void setListViewHeightBasedOnChildren(ListView listView)
   {
       ListAdapter listAdapter = listView.getAdapter();
       if (listAdapter == null)
{
           // pre-condition
           return;
       }

       int totalHeight = 0;
       for (int i = 0; i < listAdapter.getCount(); i++)
{
           View listItem = listAdapter.getView(i, null, listView);
           listItem.measure(0, 0);
           totalHeight += listItem.getMeasuredHeight();
       }

       ViewGroup.LayoutParams params = listView.getLayoutParams();
       params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
       listView.setLayoutParams(params);
   }
 
Example 8
Project: Swap   File: PLA_AbsListView.java   View source code 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addTouchables(ArrayList<View> views) {
    final int count = getChildCount();
    final int firstPosition = mFirstPosition;
    final ListAdapter adapter = mAdapter;

    if (adapter == null) {
        return;
    }

    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (adapter.isEnabled(firstPosition + i)) {
            views.add(child);
        }
        child.addTouchables(views);
    }
}
 
Example 9
Project: aos-Video   File: FolderPicker.java   View source code 6 votes vote down vote up
@Override
public void onListingUpdate(List<? extends MetaFile2> files) {

    Resources res = getResources();
    // Get the folders only
    mListItems = new ArrayList<Item>(files.size());
    for (MetaFile2 file : files) {
        Item item = new Item();
        item.mUri = file.getUri();
        if (file.isDirectory()) {
            item.mHolder = res.getDrawable(R.drawable.filetype_music_folder);
            item.mEnabled = true; // Only the folders are enabled
        } else {
            item.mHolder = res.getDrawable(R.drawable.filetype_generic2);
            item.mEnabled = false; // Only the folders are enabled
        }
        mListItems.add(item);
    }

    ListAdapter la = new FolderArrayAdapter(getActivity(), android.R.layout.simple_list_item_1);
    mListView.setAdapter(la);
}
 
Example 10
Project: weex-3d-map   File: LoadPackagesAsyncTask.java   View source code 6 votes vote down vote up
@Override
protected void onPostExecute(final List<AppInfo> results) {    
  ListAdapter listAdapter = new ArrayAdapter<AppInfo>(activity, 
                                                      R.layout.app_picker_list_item,
                                                      R.id.app_picker_list_item_label, 
                                                      results) {
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View view = super.getView(position, convertView, parent);
      Drawable icon = results.get(position).getIcon();
      if (icon != null) {
        ((ImageView) view.findViewById(R.id.app_picker_list_item_icon)).setImageDrawable(icon);
      }
      return view;
    }
  };
  activity.setListAdapter(listAdapter);
}
 
Example 11
Project: letv   File: ListFragment.java   View source code 6 votes vote down vote up
public void setListAdapter(ListAdapter adapter) {
    boolean z = false;
    boolean hadAdapter;
    if (this.mAdapter != null) {
        hadAdapter = true;
    } else {
        hadAdapter = false;
    }
    this.mAdapter = adapter;
    if (this.mList != null) {
        this.mList.setAdapter(adapter);
        if (!this.mListShown && !hadAdapter) {
            if (getView().getWindowToken() != null) {
                z = true;
            }
            setListShown(true, z);
        }
    }
}
 
Example 12
Project: FlickLauncher   File: Utilities.java   View source code 6 votes vote down vote up
public static void showNotificationDialogPRO(Activity activity){
    ArrayList<Bitmap> iconsBit = new ArrayList<>();

    for(Drawable d : MyNotificationListenerService.icons){
        iconsBit.add(Utils.convertDrawableToBitmap(d));
    }

    ListAdapter adapter = new ArrayAdapterWithIcon(activity, MyNotificationListenerService.names, iconsBit);

    new AlertDialog.Builder(activity).setTitle(MyNotificationListenerService.TITLE)
            .setAdapter(adapter, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int item) {

                }
            }).show();
}
 
Example 13
Project: FlickLauncher   File: Utilities.java   View source code 6 votes vote down vote up
private static void showIconInPack(final Activity activity, String packName, final ShortcutInfo shortcutInfo){

        String packNamePackage = null;
        for (AppInfo app : AllAppsList.data) {
            if(app.title.equals(packName)){
                packNamePackage = app.getTargetComponent().getPackageName();
            }
        }

        items.clear();
        icons.clear();
        final HashMap<String, Bitmap> map = new HashMap<>(getIconPack(packNamePackage));

        ListAdapter adapter = new ArrayAdapterWithIcon(activity, items, icons);

        new AlertDialog.Builder(activity).setTitle(activity.getString(R.string.alert_choose_app))
                .setAdapter(adapter, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {
                        saveBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName(), icons.get(item));
                        //Launcher.getLauncherAppState().reloadWorkspace();
                    }
                }).show();
    }
 
Example 14
Project: boohee_v5.6   File: ListFragment.java   View source code 6 votes vote down vote up
public void setListAdapter(ListAdapter adapter) {
    boolean z = false;
    boolean hadAdapter;
    if (this.mAdapter != null) {
        hadAdapter = true;
    } else {
        hadAdapter = false;
    }
    this.mAdapter = adapter;
    if (this.mList != null) {
        this.mList.setAdapter(adapter);
        if (!this.mListShown && !hadAdapter) {
            if (getView().getWindowToken() != null) {
                z = true;
            }
            setListShown(true, z);
        }
    }
}
 
Example 15
Project: FreeStreams-TVLauncher   File: Tools.java   View source code 6 votes vote down vote up
/**
 * @author sunglasses
 * @param listView
 * @category 计算listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		return;
	}

	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++) {
		View listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		totalHeight += listItem.getMeasuredHeight();
	}

	ViewGroup.LayoutParams params = listView.getLayoutParams();
	params.height = totalHeight
			+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	listView.setLayoutParams(params);
}
 
Example 16
Project: ZXingAndroidExt   File: LoadPackagesAsyncTask.java   View source code 6 votes vote down vote up
@Override
protected void onPostExecute(final List<AppInfo> results) {
    ListAdapter listAdapter = new ArrayAdapter<AppInfo>(activity,
            R.layout.app_picker_list_item,
            R.id.app_picker_list_item_label,
            results) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            Drawable icon = results.get(position).getIcon();
            if (icon != null) {
                ((ImageView) view.findViewById(R.id.app_picker_list_item_icon)).setImageDrawable(icon);
            }
            return view;
        }
    };
    activity.setListAdapter(listAdapter);
}
 
Example 17
Project: HiBangClient   File: RegSchoolActivity.java   View source code 6 votes vote down vote up
/***
 * 动态设置listview的高度
 * 
 * @param listView
 */
public void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		return;
	}
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++) {
		View listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		totalHeight += listItem.getMeasuredHeight();
	}
	ViewGroup.LayoutParams params = listView.getLayoutParams();
	params.height = totalHeight
			+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	// params.height += 5;// if without this statement,the listview will be
	// a
	// little short
	// listView.getDividerHeight()获取子项间分隔符占用的高度
	// params.height最后得到整个ListView完整显示需要的高度
	listView.setLayoutParams(params);
}
 
Example 18
Project: XinFramework   File: ViewFinder.java   View source code 6 votes vote down vote up
/**
 * 动态设置ListView的高度
 * @param listView ListView
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    if(listView == null) return;

    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
}
 
Example 19
Project: exciting-app   File: AbsHListView.java   View source code 6 votes vote down vote up
@Override
public void run() {
	// The data has changed since we posted this action in the event
	// queue,
	// bail out before bad things happen
	if (mDataChanged)
		return;

	final ListAdapter adapter = mAdapter;
	final int motionPosition = mClickMotionPosition;
	if (adapter != null && mItemCount > 0
			&& motionPosition != INVALID_POSITION
			&& motionPosition < adapter.getCount() && sameWindow()) {
		final View view = getChildAt(motionPosition - mFirstPosition);
		// If there is no view, something bad happened (the view
		// scrolled off the
		// screen, etc.) and we should cancel the click
		if (view != null) {
			performItemClick(view, motionPosition,
					adapter.getItemId(motionPosition));
		}
	}
}
 
Example 20
Project: lrs_android   File: DisplayUtil.java   View source code 6 votes vote down vote up
/**
 * 修正listview高度
 */
public static void setListViewHeightBasedOnChildren(ListView listView) {
    // 获取ListView对应的Adapter
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    int totalHeight = 0;
    for (int i = 0; i < listAdapter.getCount(); i++) { // listAdapter.getCount()返回数据项的数目
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(0, 0); // 计算子项View 的宽高
        totalHeight += listItem.getMeasuredHeight(); // 统计所有子项的总高度
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, totalHeight
            + (listView.getDividerHeight() * (listAdapter.getCount() - 1)));
    listView.setLayoutParams(lp);
}
 
Example 21
Project: Idea-ChainSelector   File: PinnedSectionListView.java   View source code 6 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {

    // assert adapter in debug mode
	if (BuildConfig.DEBUG && adapter != null) {
		if (!(adapter instanceof PinnedSectionListAdapter))
			throw new IllegalArgumentException("Does your adapter implement PinnedSectionListAdapter?");
		if (adapter.getViewTypeCount() < 2)
			throw new IllegalArgumentException("Does your adapter handle at least two types" +
					" of views in getViewTypeCount() method: items and sections?");
	}

	// unregister observer at old adapter and register on new one
	ListAdapter oldAdapter = getAdapter();
	if (oldAdapter != null) oldAdapter.unregisterDataSetObserver(mDataSetObserver);
	if (adapter != null) adapter.registerDataSetObserver(mDataSetObserver);

	// destroy pinned shadow, if new adapter is not same as old one
	if (oldAdapter != adapter) destroyPinnedShadow();

	super.setAdapter(adapter);
}
 
Example 22
Project: RabbitCloud   File: SmallToolsHelper.java   View source code 6 votes vote down vote up
/**
 * 根据子item的高度 动态测量GridView的实际高度
 * @param gridView
 */
public static void setGridViewHeightByChildren(GridView gridView) {
    ListAdapter listAdapter = gridView.getAdapter();
    if (listAdapter == null) {
        return;
    }
    //总高度
    int totalHeight = 0;
    int lineNum = gridView.getNumColumns(); //得到布局文件中设置的一行显示几个
    View item = listAdapter.getView(0,null,gridView);
    item.measure(0,0); //计算子item的高度
    //得到总高度
    totalHeight = item.getMeasuredHeight()*lineNum;

    ViewGroup.LayoutParams params = gridView.getLayoutParams();
    params.height = totalHeight;
    gridView.setLayoutParams(params);
}
 
Example 23
Project: AndroidMuseumBleManager   File: MergeSpinnerAdapter.java   View source code 6 votes vote down vote up
public View getDropDownView(int position, View convertView,
                            ViewGroup parent) {
    for (ListAdapter piece : getPieces()) {
        int size = piece.getCount();

        if (position < size) {
            return (((SpinnerAdapter) piece).getDropDownView(position,
                    convertView,
                    parent));
        }

        position -= size;
    }

    return (null);
}
 
Example 24
Project: qmui   File: QMUIAnimationListView.java   View source code 5 votes vote down vote up
public <T extends ListAdapter> void manipulateWithoutAnimation(final Manipulator<T> manipulator) {
    Log.i(TAG, "manipulateWithoutAnimation");
    if (!mIsAnimating) {
        manipulator.manipulate((T) mRealAdapter);
        mWrapperAdapter.notifyDataSetChanged();
    } else {
        mPendingManipulationsWithoutAnimation.add(manipulator);
    }
}
 
Example 25
Project: NoticeDog   File: DragSortListView.java   View source code 5 votes vote down vote up
/**
 * As opposed to {@link ListView#getAdapter()}, which returns
 * a heavily wrapped ListAdapter (DragSortListView wraps the
 * input ListAdapter {\emph and} ListView wraps the wrapped one).
 *
 * @return The ListAdapter set as the argument of {@link setAdapter()}
 */
public ListAdapter getInputAdapter() {
    if (mAdapterWrapper == null) {
        return null;
    } else {
        return mAdapterWrapper.getAdapter();
    }
}
 
Example 26
Project: letv   File: HListView.java   View source code 5 votes vote down vote up
protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
    super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    ListAdapter adapter = this.mAdapter;
    int closetChildIndex = -1;
    int closestChildLeft = 0;
    if (!(adapter == null || !gainFocus || previouslyFocusedRect == null)) {
        previouslyFocusedRect.offset(getScrollX(), getScrollY());
        if (adapter.getCount() < getChildCount() + this.mFirstPosition) {
            this.mLayoutMode = 0;
            layoutChildren();
        }
        Rect otherRect = this.mTempRect;
        int minDistance = Integer.MAX_VALUE;
        int childCount = getChildCount();
        int firstPosition = this.mFirstPosition;
        for (int i = 0; i < childCount; i++) {
            if (adapter.isEnabled(firstPosition + i)) {
                View other = getChildAt(i);
                other.getDrawingRect(otherRect);
                offsetDescendantRectToMyCoords(other, otherRect);
                int distance = AbsHListView.getDistance(previouslyFocusedRect, otherRect, direction);
                if (distance < minDistance) {
                    minDistance = distance;
                    closetChildIndex = i;
                    closestChildLeft = other.getLeft();
                }
            }
        }
    }
    if (closetChildIndex >= 0) {
        setSelectionFromLeft(this.mFirstPosition + closetChildIndex, closestChildLeft);
    } else {
        requestLayout();
    }
}
 
Example 27
Project: Smarty-Streets-AutoCompleteTextView   File: SmartyStreetsAutocompleteTextView.java   View source code 5 votes vote down vote up
/**
 * @param adapter the adapter for displaying the list of results in the popup window, must
 *                extend {@link AbstractAddressAutocompleteAdapter} to maintain certain logic
 */
@Override
public final <T extends ListAdapter & Filterable> void setAdapter(@NonNull final T adapter) {
    if (!(adapter instanceof AbstractAddressAutocompleteAdapter)) {
        throw new IllegalArgumentException("Custom adapters must inherit from " + AbstractAddressAutocompleteAdapter.class.getSimpleName());
    }

    this.adapter = (AbstractAddressAutocompleteAdapter) adapter;

    historyManager = this.adapter.getHistoryManager();
    api = this.adapter.getApi();

    super.setAdapter(adapter);
}
 
Example 28
Project: GitHub   File: XListView.java   View source code 5 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {
	// make sure XListViewFooter is the last footer view, and only add once.
	if (mIsFooterReady == false) {
		mIsFooterReady = true;
		addFooterView(mFooterView);
		isFooterAdded = true;
	}
	super.setAdapter(adapter);
}
 
Example 29
Project: GitHub   File: XListView.java   View source code 5 votes vote down vote up
public void setAdapterNoFooter(ListAdapter adapter) {
	// make sure XListViewFooter is the last footer view, and only add once.
	if (mIsFooterReady == false) {
		mIsFooterReady = true;

	}
	super.setAdapter(adapter);
}
 
Example 30
Project: aos-Video   File: HeaderGridView.java   View source code 5 votes vote down vote up
public HeaderViewGridAdapter(ArrayList<FixedViewInfo> headerViewInfos, ListAdapter adapter) {
    mAdapter = adapter;
    mIsFilterable = adapter instanceof Filterable;
    if (headerViewInfos == null) {
        throw new IllegalArgumentException("headerViewInfos cannot be null");
    }
    mHeaderViewInfos = headerViewInfos;
    mAreAllFixedViewsSelectable = areAllListInfosSelectable(mHeaderViewInfos);
}
 
Example 31
Project: Swap   File: PLA_ListView.java   View source code 5 votes vote down vote up
/**
 * Find a position that can be selected (i.e., is not a separator).
 *
 * @param position The starting position to look at.
 * @param lookDown Whether to look down for other positions.
 * @return The next selectable position starting at position and then searching either up or
 *         down. Returns {@link #INVALID_POSITION} if nothing can be found.
 */
@Override
int lookForSelectablePosition(int position, boolean lookDown) {
    final ListAdapter adapter = mAdapter;
    if (adapter == null || isInTouchMode()) {
        return INVALID_POSITION;
    }

    final int count = adapter.getCount();
    if (!mAreAllItemsSelectable) {
        if (lookDown) {
            position = Math.max(0, position);
            while (position < count && !adapter.isEnabled(position)) {
                position++;
            }
        } else {
            position = Math.min(position, count - 1);
            while (position >= 0 && !adapter.isEnabled(position)) {
                position--;
            }
        }

        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    } else {
        if (position < 0 || position >= count) {
            return INVALID_POSITION;
        }
        return position;
    }
}
 
Example 32
Project: PlusGram   File: SectionsListView.java   View source code 5 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {
    if (mAdapter == adapter) {
        return;
    }
    pinnedHeader = null;
    if (adapter instanceof BaseSectionsAdapter) {
        mAdapter = (BaseSectionsAdapter) adapter;
    } else {
        mAdapter = null;
    }
    super.setAdapter(adapter);
}
 
Example 33
Project: Virtualview-Android   File: DemoListActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(android.R.layout.list_content);
    List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    //HashMap<String, String> main = new HashMap<String, String>();
    //main.put("name", "Main(TODO)");
    //main.put("class", MainActivity.class.getName());
    //list.add(main);
    HashMap<String, String> api = new HashMap<String, String>();
    api.put("name", "Components");
    api.put("class", ComponentListActivity.class.getName());
    list.add(api);
    HashMap<String, String> bizItems = new HashMap<String, String>();
    bizItems.put("name", "TmallComponents");
    bizItems.put("class", TmallComponentListActivity.class.getName());
    list.add(bizItems);
    HashMap<String, String> script = new HashMap<String, String>();
    script.put("name", "Scripts(Experimental)");
    script.put("class", ScriptListActivity.class.getName());
    list.add(script);
    HashMap<String, String> parse = new HashMap<String, String>();
    parse.put("name", "Parse XML");
    parse.put("class", ParserDemoActivity.class.getName());
    list.add(parse);
    ListAdapter listAdapter = new SimpleAdapter(this, list, android.R.layout.simple_list_item_1, new String[]{"name"}, new int[]{android.R.id.text1});
    setListAdapter(listAdapter);
}
 
Example 34
Project: GitHub   File: SwipeRefreshListFragmentFragment.java   View source code 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    /**
     * Create an ArrayAdapter to contain the data for the ListView. Each item in the ListView
     * uses the system-defined simple_list_item_1 layout that contains one TextView.
     */
    ListAdapter adapter = new ArrayAdapter<String>(
            getActivity(),
            android.R.layout.simple_list_item_1,
            android.R.id.text1,
            Cheeses.randomList(LIST_ITEM_COUNT));

    // Set the adapter between the ListView and its backing data.
    setListAdapter(adapter);

    // BEGIN_INCLUDE (setup_refreshlistener)
    /**
     * Implement {@link SwipeRefreshLayout.OnRefreshListener}. When users do the "swipe to
     * refresh" gesture, SwipeRefreshLayout invokes
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}. In
     * {@link SwipeRefreshLayout.OnRefreshListener#onRefresh onRefresh()}, call a method that
     * refreshes the content. Call the same method in response to the Refresh action from the
     * action bar.
     */
    setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Log.i(LOG_TAG, "onRefresh called from SwipeRefreshLayout");

            initiateRefresh();
        }
    });
    // END_INCLUDE (setup_refreshlistener)
}
 
Example 35
Project: LocationProvider   File: StartActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start);


    setTitle(R.string.title_main);
    ListAdapter adapter = new CustomArrayAdapter(
            this.getApplicationContext(), demos);
    setListAdapter(adapter);
}
 
Example 36
Project: APIJSON-Android-RxJava   File: XListView.java   View source code 5 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {
	// make sure XListViewFooter is the last footer view, and only add once.
	if (mIsFooterReady == false) {
		mIsFooterReady = true;
		addFooterView(mFooterView);
		isFooterAdded = true;
	}
	super.setAdapter(adapter);
}
 
Example 37
Project: letv   File: PullToRefreshExpandableListView.java   View source code 5 votes vote down vote up
protected void setRefreshingInternal(boolean doScroll) {
    ListAdapter adapter = ((ExpandableListView) this.mRefreshableView).getAdapter();
    if (adapter == null || adapter.isEmpty()) {
        super.setRefreshingInternal(doScroll);
        return;
    }
    PullToRefreshHeaderView originalLoadingLayout;
    PullToRefreshHeaderView listViewLoadingLayout;
    int selection;
    int scrollToY;
    super.setRefreshingInternal(false);
    switch (getCurrentMode()) {
        case 2:
            originalLoadingLayout = getFooterLayout();
            listViewLoadingLayout = this.mFooterLoadingView;
            selection = ((ExpandableListView) this.mRefreshableView).getCount() - 1;
            scrollToY = getScrollY() - getHeaderHeight();
            break;
        default:
            originalLoadingLayout = getHeaderLayout();
            listViewLoadingLayout = this.mHeaderLoadingView;
            selection = 0;
            scrollToY = getScrollY() + getHeaderHeight();
            break;
    }
    if (doScroll) {
        setHeaderScroll(scrollToY);
    }
    originalLoadingLayout.setVisibility(4);
    listViewLoadingLayout.setParams(this.objs);
    listViewLoadingLayout.setVisibility(0);
    listViewLoadingLayout.refreshing();
    if (doScroll) {
        ((ExpandableListView) this.mRefreshableView).setSelection(selection);
        smoothScrollTo(0);
    }
}
 
Example 38
Project: JYTagView   File: SkillFlowTagLayout.java   View source code 5 votes vote down vote up
/**
 * 像ListView、GridView一样使用FlowLayout
 *
 * @param adapter
 */
public void setAdapter(ListAdapter adapter) {
    if (mAdapter != null && mDataSetObserver != null) {
        mAdapter.unregisterDataSetObserver(mDataSetObserver);
    }

    //清除现有的数据
    removeAllViews();
    mAdapter = adapter;

    if (mAdapter != null) {
        mDataSetObserver = new AdapterDataSetObserver();
        mAdapter.registerDataSetObserver(mDataSetObserver);
    }
}
 
Example 39
Project: sctalk   File: PullToRefreshListViewForNoneHeaderDivider.java   View source code 5 votes vote down vote up
@Override
public void setAdapter(ListAdapter adapter) {
	// Add the Footer View at the last possible moment
	if (null != mLvFooterLoadingFrame && !mAddedLvFooter) {
		addFooterView(mLvFooterLoadingFrame, null, false);
		mAddedLvFooter = true;
	}

	super.setAdapter(adapter);
}
 
Example 40
Project: ankihelper   File: Collins.java   View source code 5 votes vote down vote up
/**
 * @param context this
 * @param layout  support_simple_spinner_dropdown_item
 * @return
 */
public ListAdapter getAutoCompleteAdapter(Context context, int layout) {
    SimpleCursorAdapter adapter =
            new SimpleCursorAdapter(context, layout,
                    null,
                    new String[]{FIELD_HWD},
                    new int[]{android.R.id.text1},
                    0
            );
    adapter.setFilterQueryProvider(
            new FilterQueryProvider() {
                @Override
                public Cursor runQuery(CharSequence constraint) {
                    return getFilterCursor(constraint.toString());
                }
            }
    );
    adapter.setCursorToStringConverter(
            new SimpleCursorAdapter.CursorToStringConverter() {
                @Override
                public CharSequence convertToString(Cursor cursor) {
                    return cursor.getString(1);
                }
            }
    );

    return adapter;
}