use of android.widget.ListView in project platform_frameworks_base by android.
the class RenderSessionImpl method postInflateProcess.
/**
* Post process on a view hierarchy that was just inflated.
* <p/>
* At the moment this only supports TabHost: If {@link TabHost} is detected, look for the
* {@link TabWidget}, and the corresponding {@link FrameLayout} and make new tabs automatically
* based on the content of the {@link FrameLayout}.
* @param view the root view to process.
* @param layoutlibCallback callback to the project.
* @param skip the view and it's children are not processed.
*/
// For the use of Pair
@SuppressWarnings("deprecation")
private void postInflateProcess(View view, LayoutlibCallback layoutlibCallback, View skip) throws PostInflateException {
if (view == skip) {
return;
}
if (view instanceof TabHost) {
setupTabHost((TabHost) view, layoutlibCallback);
} else if (view instanceof QuickContactBadge) {
QuickContactBadge badge = (QuickContactBadge) view;
badge.setImageToDefault();
} else if (view instanceof AdapterView<?>) {
// get the view ID.
int id = view.getId();
BridgeContext context = getContext();
// get a ResourceReference from the integer ID.
ResourceReference listRef = context.resolveId(id);
if (listRef != null) {
SessionParams params = getParams();
AdapterBinding binding = params.getAdapterBindings().get(listRef);
// if there was no adapter binding, trying to get it from the call back.
if (binding == null) {
binding = layoutlibCallback.getAdapterBinding(listRef, context.getViewKey(view), view);
}
if (binding != null) {
if (view instanceof AbsListView) {
if ((binding.getFooterCount() > 0 || binding.getHeaderCount() > 0) && view instanceof ListView) {
ListView list = (ListView) view;
boolean skipCallbackParser = false;
int count = binding.getHeaderCount();
for (int i = 0; i < count; i++) {
Pair<View, Boolean> pair = context.inflateView(binding.getHeaderAt(i), list, false, skipCallbackParser);
if (pair.getFirst() != null) {
list.addHeaderView(pair.getFirst());
}
skipCallbackParser |= pair.getSecond();
}
count = binding.getFooterCount();
for (int i = 0; i < count; i++) {
Pair<View, Boolean> pair = context.inflateView(binding.getFooterAt(i), list, false, skipCallbackParser);
if (pair.getFirst() != null) {
list.addFooterView(pair.getFirst());
}
skipCallbackParser |= pair.getSecond();
}
}
if (view instanceof ExpandableListView) {
((ExpandableListView) view).setAdapter(new FakeExpandableAdapter(listRef, binding, layoutlibCallback));
} else {
((AbsListView) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
}
} else if (view instanceof AbsSpinner) {
((AbsSpinner) view).setAdapter(new FakeAdapter(listRef, binding, layoutlibCallback));
}
}
}
} else if (view instanceof ViewGroup) {
mInflater.postInflateProcess(view);
ViewGroup group = (ViewGroup) view;
final int count = group.getChildCount();
for (int c = 0; c < count; c++) {
View child = group.getChildAt(c);
postInflateProcess(child, layoutlibCallback, skip);
}
}
}
use of android.widget.ListView in project Android-MaterialRefreshLayout by android-cjj.
the class SunActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listview);
String[] array = new String[50];
for (int i = 0; i < array.length; i++) {
array[i] = "啊哈哈哈哈哈 " + i;
}
final ListView listView = (ListView) findViewById(R.id.lv);
listView.setAdapter(new android.widget.ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, array));
materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id.refresh);
materialRefreshLayout.setSunStyle(true);
materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
@Override
public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) {
materialRefreshLayout.postDelayed(new Runnable() {
@Override
public void run() {
materialRefreshLayout.finishRefresh();
}
}, 3000);
}
@Override
public void onfinish() {
Toast.makeText(SunActivity.this, "finish", Toast.LENGTH_LONG).show();
}
});
}
use of android.widget.ListView in project ListViewAnimations by nhaarman.
the class AdapterViewUtil method getViewForPosition.
/**
* Returns the {@link View} that represents the item for given position.
*
* @param listViewWrapper the {@link ListViewWrapper} wrapping the ListView that should be examined
* @param position the position for which the {@code View} should be returned.
*
* @return the {@code View}, or {@code null} if the position is not currently visible.
*/
@Nullable
public static View getViewForPosition(@NonNull final ListViewWrapper listViewWrapper, final int position) {
int childCount = listViewWrapper.getChildCount();
View downView = null;
for (int i = 0; i < childCount && downView == null; i++) {
View child = listViewWrapper.getChildAt(i);
if (child != null && getPositionForView(listViewWrapper, child) == position) {
downView = child;
}
}
return downView;
}
use of android.widget.ListView in project ListViewAnimations by nhaarman.
the class AbsListViewWrapperTest method testListViewGetHeaderViewsCount.
public void testListViewGetHeaderViewsCount() {
ListView listView = mock(ListView.class);
mAbsListViewWrapper = new AbsListViewWrapper(listView);
when(listView.getHeaderViewsCount()).thenReturn(5);
assertThat(mAbsListViewWrapper.getHeaderViewsCount(), is(5));
}
use of android.widget.ListView in project android-demos by novoda.
the class JsonRequest method onResume.
@Override
protected void onResume() {
super.onResume();
Toast.makeText(this, "Querying droidcon on Twitter", Toast.LENGTH_SHORT).show();
Reader reader = new InputStreamReader(retrieveStream(url));
SearchResponse response = new Gson().fromJson(reader, SearchResponse.class);
List<String> searches = new ArrayList<String>();
Iterator<Result> i = response.results.iterator();
while (i.hasNext()) {
Result res = (Result) i.next();
searches.add(res.text);
}
ListView v = (ListView) findViewById(R.id.list);
v.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, searches.toArray(new String[searches.size()])));
}
Aggregations