If you think the Android project PullToRefresh listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2013 Chris Banes/*www.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package uk.co.senab.actionbarpulltorefresh.samples.actionbarsherlock;
import com.actionbarsherlock.app.SherlockListActivity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
publicclass MainActivity extends SherlockListActivity {
@Override
protectedvoid onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(getSampleAdapter());
}
@Override
protectedvoid onListItemClick(ListView l, View v, int position, long id) {
ActivityInfo info = (ActivityInfo) l.getItemAtPosition(position);
Intent intent = new Intent();
intent.setComponent(new ComponentName(this, info.name));
startActivity(intent);
}
private ListAdapter getSampleAdapter() {
ArrayList<ActivityInfo> items = new ArrayList<ActivityInfo>();
final String thisClazzName = getClass().getName();
try {
PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(),
PackageManager.GET_ACTIVITIES);
ActivityInfo[] aInfos = pInfo.activities;
for (ActivityInfo aInfo : aInfos) {
if (!thisClazzName.equals(aInfo.name)) {
items.add(aInfo);
}
}
} catch (NameNotFoundException e) {
e.printStackTrace();
}
returnnew SampleAdapter(this, items);
}
privatestaticclass SampleAdapter extends BaseAdapter {
privatefinal ArrayList<ActivityInfo> mItems;
privatefinal LayoutInflater mInflater;
public SampleAdapter(Context context, ArrayList<ActivityInfo> activities) {
mItems = activities;
mInflater = LayoutInflater.from(context);
}
@Override
publicint getCount() {
return mItems.size();
}
@Override
public ActivityInfo getItem(int position) {
return mItems.get(position);
}
@Override
publiclong getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView tv = (TextView) convertView;
if (tv == null) {
tv = (TextView) mInflater.inflate(android.R.layout.simple_list_item_1, parent,
false);
}
ActivityInfo item = getItem(position);
if (!TextUtils.isEmpty(item.nonLocalizedLabel)) {
tv.setText(item.nonLocalizedLabel);
} else {
tv.setText(item.labelRes);
}
return tv;
}
}
}