List of usage examples for android.view View setOnClickListener
public void setOnClickListener(@Nullable OnClickListener l)
From source file:com.astuetz.viewpager.extensions.ScrollingTabsView.java
/** * Initialize and add all tabs to the layout *///from www. j a va2s . c o m private void initTabs() { mContainer.removeAllViews(); mTabs.clear(); if (mAdapter == null) return; for (int i = 0; i < mPager.getAdapter().getCount(); i++) { final int index = i; View tab = mAdapter.getView(i); mContainer.addView(tab); tab.setFocusable(true); mTabs.add(tab); if (i != mPager.getAdapter().getCount() - 1) { mContainer.addView(getSeparator()); } tab.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mClickListener != null) mClickListener.onClick(index); if (mPager.getCurrentItem() == index) selectTab(index); else mPager.setCurrentItem(index); } }); } selectTab(mPager.getCurrentItem()); }
From source file:net.sourceforge.kalimbaradio.androidapp.activity.SelectPlaylistActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.select_playlist); // appUtil = new ShareExternalServer(); // regId = getRegistrationId(); session = new SessionManager(getApplicationContext()); //regId = getIntent().getStringExtra("regId"); final SharedPreferences prefs = getSharedPreferences(MainActivity.class.getSimpleName(), Context.MODE_PRIVATE); regId = prefs.getString(REG_ID, ""); Log.d("MainActivity", "regId: " + regId); //if(!session.isUserCreated()) { validateSubsonicUser();//from ww w. j a v a 2 s. c o m // } /*if(!session.isUserReg()) { validateSubsonicUserReg(); }*/ final Context context = this; /* if (!TextUtils.isEmpty(regId)) { shareRegidTask = new AsyncTask<Void, Void, String>() { @Override protected String doInBackground(Void... params) { String result = appUtil.shareRegIdWithAppServer(context, regId); return result; } @Override protected void onPostExecute(String result) { shareRegidTask = null; *//* Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG).show();*//* } }; shareRegidTask.execute(null, null, null); } */ list = (ListView) findViewById(R.id.select_playlist_list); emptyTextView = findViewById(R.id.select_playlist_empty); list.setOnItemClickListener(this); registerForContextMenu(list); // Title: Playlists setTitle(R.string.playlist_label); // Button 1: refresh ImageButton refreshButton = (ImageButton) findViewById(R.id.action_button_1); refreshButton.setImageResource(R.drawable.action_refresh); refreshButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { refresh(); } }); // Button 2: search ImageButton actionSearchButton = (ImageButton) findViewById(R.id.action_button_2); actionSearchButton.setImageResource(R.drawable.action_search); actionSearchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { onSearchRequested(); } }); // Button 3: overflow final View overflowButton = findViewById(R.id.action_button_3); overflowButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new PopupMenuHelper().showMenu(SelectPlaylistActivity.this, overflowButton, R.menu.main); } }); load(); }
From source file:ca.rmen.android.scrumchatter.member.list.MembersCursorAdapter.java
/** * Set up the view with the data from the given team member * //from ww w .j av a2s . com * @param view * a newly created, or recycled view * @param cursor * a row for a given team member. */ @Override public void bindView(View view, Context context, Cursor cursor) { // Get the data from the cursor @SuppressWarnings("resource") MemberCursorWrapper memberCursorWrapper = new MemberCursorWrapper(cursor); Long memberId = memberCursorWrapper.getId(); String memberName = memberCursorWrapper.getName(); Integer avgDuration = memberCursorWrapper.getAverageDuration(); Integer sumDuration = memberCursorWrapper.getSumDuration(); Member cache = new Member(memberId, memberName); // Find the views we need to update TextView tvName = ViewHolder.get(view, R.id.tv_name); TextView tvAvgDuration = ViewHolder.get(view, R.id.tv_avg_duration); TextView tvSumDuration = ViewHolder.get(view, R.id.tv_sum_duration); View btnDelete = ViewHolder.get(view, R.id.btn_delete_member); // Setup our views with the member data tvName.setText(memberName); tvAvgDuration.setText(DateUtils.formatElapsedTime(avgDuration)); tvSumDuration.setText(DateUtils.formatElapsedTime(sumDuration)); // Forward clicks to our OnClickListener, and use the tag // to pass data about the member that the OnClickListener needs. btnDelete.setOnClickListener(mOnClickListener); btnDelete.setTag(cache); }
From source file:cn.bingoogolapple.androidcommon.adapter.BGAViewHolderHelper.java
/** * idviewIditem??//from w w w . jav a 2 s. com * * @param viewId */ public void setItemChildClickListener(@IdRes int viewId) { View view = getView(viewId); if (view != null) { view.setOnClickListener(new BGAOnNoDoubleClickListener() { @Override public void onNoDoubleClick(View v) { if (mOnItemChildClickListener != null) { if (mRecyclerView != null) { mOnItemChildClickListener.onItemChildClick(mRecyclerView, v, getPosition()); } else if (mAdapterView != null) { mOnItemChildClickListener.onItemChildClick(mAdapterView, v, getPosition()); } } } }); } }
From source file:net.reichholf.dreamdroid.activities.VirtualRemoteActivity.java
/** * Registers an OnClickListener for a specific GUI Element. OnClick the * function <code>onButtonClicked</code> will be called with the given id * //from www. j a va 2 s. c om * @param v * The view to register an OnClickListener for * @param id * The item ID to register the listener for */ protected void registerOnClickListener(View v, final int id) { v.setLongClickable(true); v.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { onButtonClicked(id, true); return true; } }); v.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { onButtonClicked(id, false); } }); }
From source file:com.cjj.viewpagerlibrary.PagerSlidingTabStrip.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); ViewGroup tabViewGroup = getTabsLayout(); if (tabViewGroup != null) { // ?????//from w ww .java 2 s .co m currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0; if (!disableViewPager) { scrollToChild(currentPosition, 0); //?? selectedTab(currentPosition); //?TAB } //?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w); itemView.setOnClickListener(this); } } }
From source file:com.android.calendar.selectcalendars.SelectCalendarsSimpleAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { if (position >= mRowCount) { return null; }/*from w ww. j ava2 s. c o m*/ String name = mData[position].displayName; boolean selected = mData[position].selected; int color = Utils.getDisplayColorFromColor(mData[position].color); View view; if (convertView == null) { view = mInflater.inflate(mLayout, parent, false); final View delegate = view.findViewById(R.id.color); final View delegateParent = (View) delegate.getParent(); delegateParent.post(new Runnable() { @Override public void run() { final Rect r = new Rect(); delegate.getHitRect(r); r.top -= mColorViewTouchAreaIncrease; r.bottom += mColorViewTouchAreaIncrease; r.left -= mColorViewTouchAreaIncrease; r.right += mColorViewTouchAreaIncrease; delegateParent.setTouchDelegate(new TouchDelegate(r, delegate)); } }); } else { view = convertView; } TextView calendarName = (TextView) view.findViewById(R.id.calendar); calendarName.setText(name); View colorView = view.findViewById(R.id.color); colorView.setBackgroundColor(color); colorView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Purely for sanity check--view should be disabled if account has no more colors if (!hasMoreColors(position)) { return; } if (mColorPickerDialog == null) { mColorPickerDialog = CalendarColorPickerDialog.newInstance(mData[position].id, mIsTablet); } else { mColorPickerDialog.setCalendarId(mData[position].id); } mFragmentManager.executePendingTransactions(); if (!mColorPickerDialog.isAdded()) { mColorPickerDialog.show(mFragmentManager, COLOR_PICKER_DIALOG_TAG); } } }); int textColor; if (selected) { textColor = mColorCalendarVisible; } else { textColor = mColorCalendarHidden; } calendarName.setTextColor(textColor); CheckBox syncCheckBox = (CheckBox) view.findViewById(R.id.sync); if (syncCheckBox != null) { // Full screen layout syncCheckBox.setChecked(selected); colorView.setEnabled(hasMoreColors(position)); LayoutParams layoutParam = calendarName.getLayoutParams(); TextView secondaryText = (TextView) view.findViewById(R.id.status); if (!TextUtils.isEmpty(mData[position].ownerAccount) && !mData[position].ownerAccount.equals(name) && !mData[position].ownerAccount.endsWith("calendar.google.com")) { int secondaryColor; if (selected) { secondaryColor = mColorCalendarSecondaryVisible; } else { secondaryColor = mColorCalendarSecondaryHidden; } secondaryText.setText(mData[position].ownerAccount); secondaryText.setTextColor(secondaryColor); secondaryText.setVisibility(View.VISIBLE); layoutParam.height = LayoutParams.WRAP_CONTENT; } else { secondaryText.setVisibility(View.GONE); layoutParam.height = LayoutParams.MATCH_PARENT; } calendarName.setLayoutParams(layoutParam); } else { // Tablet layout view.findViewById(R.id.color).setEnabled(selected && hasMoreColors(position)); view.setBackgroundDrawable(getBackground(position, selected)); ViewGroup.LayoutParams newParams = view.getLayoutParams(); if (position == mData.length - 1) { newParams.height = BOTTOM_ITEM_HEIGHT; } else { newParams.height = NORMAL_ITEM_HEIGHT; } view.setLayoutParams(newParams); CheckBox visibleCheckBox = (CheckBox) view.findViewById(R.id.visible_check_box); if (visibleCheckBox != null) { visibleCheckBox.setChecked(selected); } } view.invalidate(); return view; }
From source file:com.tdispatch.passenger.fragment.BookingListFragment.java
@Override protected void onPostCreateView() { mPullListview = (PullToRefreshListView) mFragmentView.findViewById(R.id.list); mPullListview.setOnRefreshListener(mListOnRefreshListener); // Set a listener to be invoked when the list should be refreshed. mMainListview = mPullListview.getRefreshableView(); // get the "real" mMainListview object to cope with mAdapter = new ListAdapter(mParentActivity, 0, mBookings); mMainListview.setAdapter(mAdapter);//from www .j a v a2s . c om int[] ids = { R.id.button_retry }; for (int id : ids) { View v = mFragmentView.findViewById(id); v.setOnClickListener(mOnClickListener); } WebnetTools.setVisibility(mFragmentView, R.id.booking_list_container, View.GONE); WebnetTools.setVisibility(mFragmentView, R.id.booking_list_empty_container, View.GONE); WebnetTools.setVisibility(mFragmentView, R.id.booking_error_container, View.GONE); downloadBookings(); }
From source file:com.android.yijiang.kzx.widget.tab.PagerSlidingTabStrip.java
@Override protected void onLayout(boolean changed, int l, int t, int r, int b) { ViewGroup tabViewGroup = getTabsLayout(); // /*from w w w . ja v a 2s. c o m*/ if (tabViewGroup == null || tabViewGroup.getChildCount() <= 0) { super.onLayout(changed, l, t, r, b); return; } int viewWidth = r - l; // Item if ((measure(tabViewGroup).getMeasuredWidth() < viewWidth) && allowWidthFull) { // ?tabViewGroup?? viewWidth -= tabViewGroup.getPaddingLeft(); viewWidth -= tabViewGroup.getPaddingRight(); if (tabViewGroup.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams tabsLayoutParams = (MarginLayoutParams) tabViewGroup.getLayoutParams(); viewWidth -= tabsLayoutParams.leftMargin; viewWidth -= tabsLayoutParams.rightMargin; } // ??Tab? View tabView; for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); if (tabView.getLayoutParams() instanceof MarginLayoutParams) { MarginLayoutParams marginLayoutParams = (MarginLayoutParams) tabView.getLayoutParams(); viewWidth -= marginLayoutParams.leftMargin; viewWidth -= marginLayoutParams.rightMargin; } } // ? int averageWidth = viewWidth / tabViewGroup.getChildCount(); int bigTabCount = 0; // ?tab??? for (int w = 0; w < tabViewGroup.getChildCount(); w++) { tabView = tabViewGroup.getChildAt(w); // ???? if (tabView != null && tabView.getMeasuredWidth() > averageWidth) { viewWidth -= tabView.getMeasuredWidth(); bigTabCount++; } } // ? averageWidth = viewWidth / (tabViewGroup.getChildCount() - bigTabCount); // ??Item for (int w = 0; w < tabViewGroup.getChildCount(); w++) { //????? tabView = tabViewGroup.getChildAt(w); if (tabView != null) { ViewGroup.LayoutParams layoutParams = tabView.getLayoutParams(); if (layoutParams != null) { layoutParams.width = tabView.getMeasuredWidth() < averageWidth ? averageWidth : tabView.getMeasuredWidth(); tabView.setLayoutParams(layoutParams); measure(tabView); } } } measure(tabViewGroup); } // ????? currentPosition = viewPager != null ? viewPager.getCurrentItem() : 0; scrollToChild(currentPosition, 0); //?? selectedTab(currentPosition); //?TAB //?tab?Pager for (int w = 0; w < tabViewGroup.getChildCount(); w++) { View itemView = tabViewGroup.getChildAt(w); itemView.setTag(w); itemView.setOnClickListener(this); } super.onLayout(changed, l, t, r, b); }
From source file:com.buddi.client.dfu.FeaturesActivity.java
private void setupPluginsInDrawer(final ViewGroup container) { final LayoutInflater inflater = LayoutInflater.from(this); final PackageManager pm = getPackageManager(); // look for Master Control Panel final Intent mcpIntent = new Intent(Intent.ACTION_MAIN); mcpIntent.setClassName(MCP_PACKAGE, MCP_CLASS); final ResolveInfo mcpInfo = pm.resolveActivity(mcpIntent, 0); // configure link to Master Control Panel final TextView mcpItem = (TextView) container.findViewById(R.id.link_mcp); if (mcpInfo == null) { mcpItem.setTextColor(Color.GRAY); ColorMatrix grayscale = new ColorMatrix(); grayscale.setSaturation(0.0f);/*from w w w . j a va 2s. co m*/ mcpItem.getCompoundDrawables()[0].setColorFilter(new ColorMatrixColorFilter(grayscale)); } mcpItem.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { Intent action = mcpIntent; if (mcpInfo == null) action = new Intent(Intent.ACTION_VIEW, Uri.parse(MCP_MARKET_URI)); action.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); try { startActivity(action); } catch (final ActivityNotFoundException e) { Toast.makeText(FeaturesActivity.this, R.string.no_application_play, Toast.LENGTH_SHORT).show(); } mDrawerLayout.closeDrawers(); } }); // look for other plug-ins final Intent utilsIntent = new Intent(Intent.ACTION_MAIN); utilsIntent.addCategory(UTILS_CATEGORY); final List<ResolveInfo> appList = pm.queryIntentActivities(utilsIntent, 0); for (final ResolveInfo info : appList) { final View item = inflater.inflate(R.layout.drawer_plugin, container, false); final ImageView icon = (ImageView) item.findViewById(android.R.id.icon); final TextView label = (TextView) item.findViewById(android.R.id.text1); label.setText(info.loadLabel(pm)); icon.setImageDrawable(info.loadIcon(pm)); item.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { final Intent intent = new Intent(); intent.setComponent(new ComponentName(info.activityInfo.packageName, info.activityInfo.name)); intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); startActivity(intent); mDrawerLayout.closeDrawers(); } }); container.addView(item); } }