下面列出了android.widget.ExpandableListView#setOnChildClickListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.channel_list, container, false);
OnChildClickListener channelItemListener = new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
JSONObject channelItem = (JSONObject) adapter.getChild(groupPosition, childPosition);
channelSelected(channelItem);
return true;
}
};
ExpandableListView channelsView = (ExpandableListView) view.findViewById(R.id.channelListView);
channelsView.setEmptyView(view.findViewById(R.id.channelListProgress));
channelsView.setAdapter(adapter);
channelsView.setOnChildClickListener(channelItemListener);
PauseOnScrollListener listener = new PauseOnScrollListener(ImageLoader.getInstance(), true, true);
channelsView.setOnScrollListener(listener);
expandAll(view);
return view;
}
/**
* Updates the screen state (current list and other views) when the
* content changes.
*
* @see Activity#onContentChanged()
*/
@Override
public void onContentChanged() {
super.onContentChanged();
View emptyView = findViewById(com.android.internal.R.id.empty);
mList = (ExpandableListView)findViewById(com.android.internal.R.id.list);
if (mList == null) {
throw new RuntimeException(
"Your content must have a ExpandableListView whose id attribute is " +
"'android.R.id.list'");
}
if (emptyView != null) {
mList.setEmptyView(emptyView);
}
mList.setOnChildClickListener(this);
mList.setOnGroupExpandListener(this);
mList.setOnGroupCollapseListener(this);
if (mFinishedStart) {
setListAdapter(mAdapter);
}
mFinishedStart = true;
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(Activity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = buildAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
onUpdated();
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(Activity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = buildAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
onUpdated();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main_doing_list,
container, false);
mDoingListData = new ArrayList<DoingListData>();
expandableListView = (ExpandableListView) rootView
.findViewById(R.id.expandableListView_doing_list);
adapter = new AnytimeExpandableListAdapter(activity);
expandableListView.setAdapter(adapter);
expandableListView.setOnChildClickListener(listener);
messageText = (TextView) rootView
.findViewById(R.id.textView_loading_wait);
LoadingData();
return rootView;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataField = (TextView) findViewById(R.id.data_value);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mlistView = new ExpandableListView(this);
mlistView.setOnGroupClickListener(this);
mlistView.setOnChildClickListener(this);
List<GroupList> groups = new ArrayList<GroupList>();
for( int i=0; i<mParentMenu.length; i++) {
List<GroupList> childs = new ArrayList<GroupList>();
for( int j=0; j<mChildMenu[i].length; j++ ) {
childs.add(new GroupListChild(mChildMenu[i][j]));
}
groups.add(new GroupListParent(mParentMenu[i],childs));
}
mAdapter = new GroupListAdapter(this,groups);
mlistView.setAdapter(mAdapter);
setContentView(mlistView);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
BleApplication app = (BleApplication) getApplication();
mBle = app.getIBle();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataField = (TextView) findViewById(R.id.data_value);
getActionBar().setTitle(mDeviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
System.out.println("DeviceControlActivity onCreate");
final Intent intent = getIntent();
mDeviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
mDeviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(mDeviceAddress);
mGattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
mGattServicesList.setOnChildClickListener(servicesListClickListner);
mConnectionState = (TextView) findViewById(R.id.connection_state);
mDataField = (TextView) findViewById(R.id.data_value);
// getActionBar().setTitle(mDeviceName);
// getActionBar().setDisplayHomeAsUpEnabled(true);
Intent gattServiceIntent = new Intent(this, BluetoothLeService.class);
bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_roots, container, false);
mList = (ExpandableListView) view.findViewById(android.R.id.list);
mList.setOnChildClickListener(mItemListener);
mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = Utils.dpToPx(302);
boolean rtl = Utils.isRTL();
int leftPadding = rtl ? 10 : 50;
int rightPadding = rtl ? 50 : 10;
int leftWidth = width - Utils.dpToPx(leftPadding);
int rightWidth = width - Utils.dpToPx(rightPadding);
if(Utils.hasJellyBeanMR2()){
mList.setIndicatorBoundsRelative(leftWidth, rightWidth);
} else {
mList.setIndicatorBounds(leftWidth, rightWidth);
}
return view;
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_roots, container, false);
mList = (ExpandableListView) view.findViewById(android.R.id.list);
mList.setOnChildClickListener(mItemListener);
mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = Utils.dpToPx(302);
boolean rtl = Utils.isRTL();
int leftPadding = rtl ? 10 : 50;
int rightPadding = rtl ? 50 : 10;
int leftWidth = width - Utils.dpToPx(leftPadding);
int rightWidth = width - Utils.dpToPx(rightPadding);
if(Utils.hasJellyBeanMR2()){
mList.setIndicatorBoundsRelative(leftWidth, rightWidth);
} else {
mList.setIndicatorBounds(leftWidth, rightWidth);
}
return view;
}
@Override
public View onCreateView(
LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_roots, container, false);
mList = (ExpandableListView) view.findViewById(android.R.id.list);
mList.setOnChildClickListener(mItemListener);
mList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = Utils.dpToPx(302);
boolean rtl = Utils.isRTL();
int leftPadding = rtl ? 10 : 50;
int rightPadding = rtl ? 50 : 10;
int leftWidth = width - Utils.dpToPx(leftPadding);
int rightWidth = width - Utils.dpToPx(rightPadding);
if(Utils.hasJellyBeanMR2()){
mList.setIndicatorBoundsRelative(leftWidth, rightWidth);
} else {
mList.setIndicatorBounds(leftWidth, rightWidth);
}
return view;
}
private void init() {
mInflater = LayoutInflater.from(this);
initData();
mAdapter = new MyExpandableListViewAdapter();
mListView = (ExpandableListView) findViewById(R.id.my_list);
mListView.setAdapter(mAdapter);
mListView.setOnGroupClickListener(this);
mListView.setOnChildClickListener(this);
mListView.setOnGroupExpandListener(this);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.device_services_activity);
gattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
gattServicesList.setOnChildClickListener(this);
final View emptyView = findViewById(R.id.empty_view);
gattServicesList.setEmptyView(emptyView);
dataCharacteristic = (TextView) findViewById(R.id.data_characteristic_uuid);
dataValue = (TextView) findViewById(R.id.data_characteristic_value);
//noinspection ConstantConditions
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
final String deviceName = getDeviceName();
if (TextUtils.isEmpty(deviceName)) {
//noinspection ConstantConditions
actionBar.setTitle(getDeviceAddress());
} else {
//noinspection ConstantConditions
actionBar.setTitle(deviceName);
actionBar.setSubtitle(getDeviceAddress());
}
actionBar.setDisplayHomeAsUpEnabled(true);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mInflater = inflater;
View v = inflater.inflate(R.layout.fragment_api_test, container, false);
mProgressDialog = new ProgressDialog(getActivity());
mProgressDialog.setMessage("Sending request...");
mExpandableListView = (ExpandableListView) v.findViewById(R.id.expandable_list_view);
mExpandableListView.setGroupIndicator(null);
initData();
mExpandableListView.setOnChildClickListener(this);
return v;
}
/**
* Constructor returns an instance of RecentTabsPage.
*
* @param activity The activity this view belongs to.
* @param recentTabsManager The RecentTabsManager which provides the model data.
*/
public RecentTabsPage(ChromeActivity activity, RecentTabsManager recentTabsManager) {
mActivity = activity;
mRecentTabsManager = recentTabsManager;
mTitle = activity.getResources().getString(R.string.recent_tabs);
mThemeColor = ApiCompatibilityUtils.getColor(
activity.getResources(), R.color.default_primary_color);
mRecentTabsManager.setUpdatedCallback(this);
LayoutInflater inflater = LayoutInflater.from(activity);
mView = (ViewGroup) inflater.inflate(R.layout.recent_tabs_page, null);
mListView = (ExpandableListView) mView.findViewById(R.id.odp_listview);
mAdapter = new RecentTabsRowAdapter(activity, recentTabsManager);
mListView.setAdapter(mAdapter);
mListView.setOnChildClickListener(this);
mListView.setGroupIndicator(null);
mListView.setOnGroupCollapseListener(this);
mListView.setOnGroupExpandListener(this);
mListView.setOnCreateContextMenuListener(this);
mView.addOnAttachStateChangeListener(this);
ApplicationStatus.registerStateListenerForActivity(this, activity);
// {@link #mInForeground} will be updated once the view is attached to the window.
if (activity.getBottomSheet() != null) {
View recentTabsRoot = mView.findViewById(R.id.recent_tabs_root);
ApiCompatibilityUtils.setPaddingRelative(recentTabsRoot,
ApiCompatibilityUtils.getPaddingStart(recentTabsRoot), 0,
ApiCompatibilityUtils.getPaddingEnd(recentTabsRoot),
activity.getResources().getDimensionPixelSize(
R.dimen.bottom_control_container_height));
}
onUpdated();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gatt_services_characteristics);
final Intent intent = getIntent();
deviceName = intent.getStringExtra(EXTRAS_DEVICE_NAME);
deviceAddress = intent.getStringExtra(EXTRAS_DEVICE_ADDRESS);
// Sets up UI references.
((TextView) findViewById(R.id.device_address)).setText(deviceAddress);
gattServicesList = (ExpandableListView) findViewById(R.id.gatt_services_list);
gattServicesList.setOnChildClickListener(servicesListClickListner);
connectionState = (TextView) findViewById(R.id.connection_state);
dataField = (TextView) findViewById(R.id.data_value);
heartRateField = (TextView) findViewById(R.id.heartrate_value);
demoButton = (Button) findViewById(R.id.demo);
demoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d(TAG, "onClick serviceListener: "+serviceListener);
if (serviceListener == null)
return;
final BluetoothGattService service = gattServiceAdapter.getHeartRateService();
serviceListener.onDemoClick(service);
Log.d(TAG, "set service listener");
}
});
demoButton.setVisibility(View.VISIBLE);
getActionBar().setTitle(deviceName);
getActionBar().setDisplayHomeAsUpEnabled(true);
final Intent gattServiceIntent = new Intent(this, BleService.class);
bindService(gattServiceIntent, serviceConnection, BIND_AUTO_CREATE);
}
private void initView(View v) {
mElv_addressbook = (ExpandableListView) v.findViewById(R.id.cgt_elv_addressbook);
mV_addressbook_right = (AssortView) v.findViewById(R.id.cgt_v_addressbook_right);
mElv_addressbook.setOnItemLongClickListener(this);
mElv_addressbook.setOnChildClickListener(this);
}
private void initView() {
m_QQClient = AppData.getAppData().getQQClient();
m_buddyList = m_QQClient.getBuddyList();
// m_btnBuddyTeam = (Button)getActivity().findViewById(R.id.contacts_btnBuddyTeam);
// m_btnAllBuddy = (Button)getActivity().findViewById(R.id.contacts_btnAllBuddy);
mListView = (ExpandableListView)getActivity().findViewById(R.id.expandableListView);
// m_btnGroup = (ImageButton)getActivity().findViewById(R.id.contacts_btnGroup);
swipeRefreshLayout_freind= (PullRefreshLayout) getActivity().findViewById(R.id.swipeRefreshLayout_friend);
// m_btnBuddyTeam.setOnClickListener(this);
// m_btnAllBuddy.setOnClickListener(this);
// m_btnGroup.setOnClickListener(this);
//ExpandableListView actualListView = mListView.getRefreshableView();
mListView.setGroupIndicator(null);
m_blistAdapter = new BuddyListAdapter(getActivity(), m_buddyList);
mListView.setAdapter(m_blistAdapter);
mListView.setDescendantFocusability(
ExpandableListView.FOCUS_AFTER_DESCENDANTS);
mListView.setOnChildClickListener(this);
// mListView.getLoadingLayoutProxy().setPullLabel("下拉刷新");
// mListView.getLoadingLayoutProxy().setReleaseLabel("释放立即刷新");
// mListView.getLoadingLayoutProxy().setRefreshingLabel("正在刷新...");
// mListView.getLoadingLayoutProxy().setLastUpdatedLabel("");
swipeRefreshLayout_freind.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
new GetDataTask().execute();
swipeRefreshLayout_freind.postDelayed(new Runnable() {
@Override
public void run() {
swipeRefreshLayout_freind.setRefreshing(false);
refresh();
// m_glistAdapter.notifyDataSetChanged();
}
}, 1000);
}
});
}