Example usage for android.widget LinearLayout setOnClickListener

List of usage examples for android.widget LinearLayout setOnClickListener

Introduction

In this page you can find the example usage for android.widget LinearLayout setOnClickListener.

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.boding.app.CitySelectActivity.java

private void initView() {
    setTitle();//from w  w  w .  j a v a2  s.c o m

    LinearLayout returnLogoLinearLayout = (LinearLayout) findViewById(R.id.return_logo_linearLayout);
    returnLogoLinearLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Util.returnToPreviousPage(CitySelectActivity.this, IntentRequestCode.CITY_SELECTION);
        }
    });

    LinearLayout citySearchLinearLayout = (LinearLayout) findViewById(R.id.city_search_linearLayout);
    citySearchLinearLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            SearchCityDialog searchCityDialog = new SearchCityDialog(CitySelectActivity.this,
                    isFlyToCitySelection);
            searchCityDialog.show();
        }
    });
}

From source file:com.ymt.demo1.main.sign.SignUpFragment.java

/**
 * ???//w  w w . j a  va  2  s. c o m
 * ?????????
 */
protected void initView(View view) {
    /*
    
     */
    //?
    final EditText phoneTxt = (EditText) view.findViewById(R.id.input_phone_num);
    final EditText accountTxt = (EditText) view.findViewById(R.id.input_account);
    final EditText pswTxt = (EditText) view.findViewById(R.id.input_psw);
    final EditText rePswTxt = (EditText) view.findViewById(R.id.re_input_psw);
    final TextView licenseTxt = (TextView) view.findViewById(R.id.licence_txt);
    /*???? ??
     */
    final TextView getCheckNums = (TextView) view.findViewById(R.id.get_check_nums);
    final EditText inputCheckNums = (EditText) view.findViewById(R.id.input_check_nums);
    getCheckNums.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //todo ????

        }
    });

    /**
     *  todo spannableString 
     *   ?
     */
    SpannableString spannableString = new SpannableString(getString(R.string.license));
    ForegroundColorSpan span = new ForegroundColorSpan(getResources().getColor(R.color.material_blue_grey_800));
    spannableString.setSpan(span, 0, 7, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    licenseTxt.setText(spannableString);
    //switch(??)
    myCheckView = (MyCheckView) view.findViewById(R.id.switch_liscense);
    //
    Button signUpBtn = (Button) view.findViewById(R.id.do_sign_btn);
    signUpBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //
            String phoneNum = phoneTxt.getText().toString();
            String account = accountTxt.getText().toString();
            String psw = pswTxt.getText().toString();
            String rePsw = rePswTxt.getText().toString();
            //??
            String checkNums = inputCheckNums.getText().toString();
            //todo if(){}else{} ??

            if (!TextUtils.isEmpty(phoneNum) && !TextUtils.isEmpty(account) && !TextUtils.isEmpty(psw)
                    && psw.equals(rePsw)) {
                //?
                if (myCheckView.isChecked()) {
                    queue.add(signUpRequest(account, psw, phoneNum, NORMAL_USER));
                } else {
                    Toast.makeText(getActivity(), "?????",
                            Toast.LENGTH_SHORT).show();
                }

            } else if (TextUtils.isEmpty(phoneNum)) {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show();
            } else if (TextUtils.isEmpty(account)) {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT).show();
            } else {
                //???
                Toast.makeText(getActivity(), "???", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    });

    LinearLayout licence = (LinearLayout) view.findViewById(R.id.liscense_layout);
    licence.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            myCheckView.callOnClick();
        }
    });
}

From source file:io.ordunaleon.lumios.ui.DrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_drawer);

    // Find and setup Toolbar to replace the ActionBar.
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w ww.ja  v a  2 s.co m*/

    // Find and setup DrawerLayout and it's ActionBarDrawerToggle.
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open,
            R.string.drawer_close);
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    // Find and setup NavigationView.
    NavigationView navigationView = (NavigationView) findViewById(R.id.navigation_view);
    navigationView.setNavigationItemSelectedListener(this);

    // Find NavigationView header.
    View headerView = navigationView.getHeaderView(0);

    // Make clickable the text in the headerView.
    LinearLayout headerTitle = (LinearLayout) headerView.findViewById(R.id.drawer_header_title);
    headerTitle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // Todo: Allow the user to change the fare rather than display a Snackbar.
            View view = v.getRootView().findViewById(R.id.frame_layout);
            Snackbar.make(view, "WIP | Select your fare", Snackbar.LENGTH_SHORT).show();
        }
    });

    // Find and setup the headerView text.
    mDrawerHeaderHead = (TextView) headerTitle.findViewById(R.id.drawer_header_head);
    mDrawerHeaderSubhead = (TextView) headerTitle.findViewById(R.id.drawer_header_subhead);
    updateDrawerHeader();

    // First run of the app starts with the Navigation Drawer open.
    if (!PrefUtils.isWelcomeDone(this)) {
        PrefUtils.setWelcomeDone(this, true);
        mDrawerLayout.openDrawer(GravityCompat.START);
    }

    if (savedInstanceState == null) {
        onNavigationItemSelected(navigationView.getMenu().findItem(DEFAULT_DRAWER_ITEM_ID));
    } else {
        setTitle(savedInstanceState.getCharSequence(KEY_STATE_TITLE));
    }

    // Check for Google Play Services and start LumiosRegistrationIntentService to register this
    // application with GCM if needed.
    if (checkPlayServices() && !PrefUtils.isAppRegistered(this)) {
        Intent intent = new Intent(this, LumiosRegistrationIntentService.class);
        startService(intent);
    }

    PrefUtils.registerOnSharedPreferenceChangeListener(this, this);
}

From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java

@Override
public @NonNull View getView(int position, View convertView, final @NonNull ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.row_alt : R.layout.row,
                parent, false);/*from   w  w w. java 2  s . com*/

    final AppEntry entry = getItem(position);
    assert entry != null;

    final SharedPreferences pref = U.getSharedPreferences(getContext());

    TextView textView = (TextView) convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());

    Intent intent = new Intent();
    intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
    ActivityInfo activityInfo = intent.resolveActivityInfo(getContext().getPackageManager(), 0);

    if (activityInfo != null)
        textView.setTypeface(null, isTopApp(activityInfo) ? Typeface.BOLD : Typeface.NORMAL);

    switch (pref.getString("theme", "light")) {
    case "light":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color));
        break;
    case "dark":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_dark));
        break;
    }

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(entry.getIcon(getContext()));

    LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        LocalBroadcastManager.getInstance(getContext())
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
        U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(),
                entry.getUserId(getContext()), null, false, false);
    });

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int backgroundTint = pref.getBoolean("transparent_start_menu", false)
                        ? U.getAccentColor(getContext())
                        : U.getBackgroundTint(getContext());

                //noinspection ResourceAsColor
                backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2);
                v.setBackgroundColor(backgroundTint);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.example.android.tourguide.ObjectAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    View listItemView = convertView;
    if (listItemView == null) {
        listItemView = LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);
    }//w ww  .j  a va  2s  . c  o m

    // Get the {@link Object} object located at this position in the list
    final Object currentObject = getItem(position);

    // Find the TextView in the list_item.xml layout with the ID name_text_view.
    TextView objectNameTV = (TextView) listItemView.findViewById(R.id.name_text_view);
    objectNameTV.setSelected(true);
    objectNameTV.setText(currentObject.getObjectName());

    // Find the TextView in the list_item.xml layout with the ID address_text_view.
    TextView addressTV = (TextView) listItemView.findViewById(R.id.address_text_view);
    addressTV.setSelected(true);
    addressTV.setText(currentObject.getObjectAddress());

    // Find the TextView in the list_item.xml layout with the ID description_text_view.
    TextView objectDescription = (TextView) listItemView.findViewById(R.id.description_text_view);
    objectDescription.setText(currentObject.getObjectDescription());

    // Find the ImageView in the list_item.xml layout with the ID image.
    final ImageView imageView = (ImageView) listItemView.findViewById(R.id.image);
    // Check if an image is provided for this word or not
    if (currentObject.hasImage()) {
        // If an image is available, display the provided image based on the resource ID
        imageView.setImageResource(currentObject.getImageResourceId());
        // Make sure the view is visible
        imageView.setVisibility(View.VISIBLE);
    } else {
        // Otherwise hide the ImageView (set visibility to GONE)
        imageView.setVisibility(View.GONE);
    }

    LinearLayout textContainer = (LinearLayout) listItemView.findViewById(R.id.text_container);
    int color = ContextCompat.getColor(getContext(), mColorResourceId);
    textContainer.setBackgroundColor(color);

    textContainer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (currentObject.hasImage()) {
                if (imageView.getVisibility() == View.GONE) {
                    imageView.setVisibility(View.VISIBLE);
                } else {
                    imageView.setVisibility(View.GONE);
                }
            }
        }
    });

    // Return the whole list item layout (containing 2 TextViews) so that it can be shown in
    // the ListView.
    return listItemView;
}

From source file:org.bwgz.quotation.activity.HomeActivity.java

@Override
protected void onCreate(Bundle bundle) {
    super.onCreate(bundle);
    Log.d(TAG, String.format("onCreate - bundle: %s", bundle));

    setContentView(R.layout.home_activity);

    drawerLayout = (DrawerLayout) findViewById(R.id.home);
    drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {//from   ww w.j  a v a2 s . com
        public void onDrawerClosed(View view) {
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            invalidateOptionsMenu();
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);

    LinearLayout quotationsNavigation = (LinearLayout) findViewById(R.id.navigation_quotations);
    quotationsNavigation.setOnClickListener(new NavigationOnClickListener(QuotationsActivity.class));
    LinearLayout authorsNavigation = (LinearLayout) findViewById(R.id.navigation_authors);
    authorsNavigation.setOnClickListener(new NavigationOnClickListener(AuthorsActivity.class));
    LinearLayout subjectsNavigation = (LinearLayout) findViewById(R.id.navigation_subjects);
    subjectsNavigation.setOnClickListener(new NavigationOnClickListener(SubjectsActivity.class));

    quotationPicksView = (PicksView) findViewById(R.id.quotation_picks);
    quotationPicksView.setActivityClass(QuotationActivity.class);
    quotationLoaderId = initLoader(this, PickQuotation.CONTENT_URI, QuotationQuery.PROJECTION, null, null,
            null);

    authorPicksView = (PicksView) findViewById(R.id.author_picks);
    authorPicksView.setActivityClass(AuthorActivity.class);
    authorLoaderId = initLoader(
            this, PickPerson.CONTENT_URI, new String[] { Person.FULL_ID, Person.NAME, Person.DESCRIPTION,
                    Person.NOTABLE_FOR, Person.IMAGE_ID, Person.QUOTATION_COUNT, BookmarkPerson.BOOKMARK_ID },
            null, null, null);

    subjectPicksView = (PicksView) findViewById(R.id.subject_picks);
    subjectPicksView.setActivityClass(SubjectActivity.class);
    subjectLoaderId = initLoader(this, PickSubject.CONTENT_URI, new String[] { Subject.FULL_ID, Subject.NAME,
            Subject.DESCRIPTION, Subject.IMAGE_ID, Subject.QUOTATION_COUNT, BookmarkSubject.BOOKMARK_ID }, null,
            null, null);

    getActionBar().setDisplayHomeAsUpEnabled(true);
}

From source file:org.ciasaboark.tacere.activity.fragment.MainSettingsFragment.java

private void drawAdvancedSettingsWidget() {
    LinearLayout advancedSettingsContainer = (LinearLayout) rootView
            .findViewById(R.id.settings_advanced_settings_container);
    if (showAdvancedSettingsLink) {
        advancedSettingsContainer.setVisibility(View.VISIBLE);
        LinearLayout advancedSettingsBox = (LinearLayout) rootView
                .findViewById(R.id.settings_advanced_settings_box);
        advancedSettingsBox.setOnClickListener(new View.OnClickListener() {
            @Override//from  w w  w .j av a 2  s .  co m
            public void onClick(View v) {
                startActivity(new Intent(context, AdvancedSettingsActivity.class));
            }
        });
    } else {
        advancedSettingsContainer.setVisibility(View.GONE);
    }
}

From source file:com.example.olivi.maphap.DetailFragment.java

private void setUpFirstCard(Cursor data) {
    //Create first card containing event title, date, and place.
    Card detailCard = new Card(getActivity(), R.layout.card_event_layout1);

    String name = data.getString(Projections.EventsDetailView.COL_NAME);

    addCardHeader(detailCard, name);//from  ww w  .j  ava  2 s .c o m

    CardViewNative cardView = (CardViewNative) getActivity().findViewById(R.id.card_event_1);
    cardView.setCard(detailCard);

    View v = cardView.getInternalContentLayout();
    long startMillis = data.getLong(Projections.EventsDetailView.COL_START_DATE_TIME);
    long endMillis = data.getLong(Projections.EventsDetailView.COL_END_DATE_TIME);

    LinearLayout addToCalendar = (LinearLayout) v.findViewById(R.id.detail_button_add_event_to_calendar);
    addToCalendar.setOnClickListener(new AddToCalendarClickListener(data));

    TextView start = (TextView) v.findViewById(R.id.detail_start_textview);
    TextView end = (TextView) v.findViewById(R.id.detail_end_textview);

    DateUtils.setUpDateTimeTextViews(DateUtils.FORMAT_DETAIL_TEXTVIEW_DATE_TIME, start, end, startMillis,
            endMillis);

    setTextView(v, R.id.detail_venue_textview, data, Projections.EventsDetailView.COL_VENUE_NAME);

    TextView urlTextView = (TextView) v.findViewById(R.id.detail_url_textview);

    urlTextView.setText(data.getString(Projections.EventsDetailView.COL_URL));
}

From source file:com.vinidsl.googleioextended.ui.fragment.ExploreFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_explore, container, false);

    LinearLayout l1 = (LinearLayout) rootView.findViewById(R.id.explore1);
    LinearLayout l2 = (LinearLayout) rootView.findViewById(R.id.explore2);
    LinearLayout l3 = (LinearLayout) rootView.findViewById(R.id.explore3);
    LinearLayout l4 = (LinearLayout) rootView.findViewById(R.id.explore4);
    l1.setOnClickListener(this);
    l2.setOnClickListener(this);
    l3.setOnClickListener(this);
    l4.setOnClickListener(this);

    List<Talk> talkList = TalkController.getLocalTalks(getActivity(), 4);

    talk1 = talkList.remove(0);/*w ww. j a v a  2s. c  om*/
    talk2 = talkList.remove(0);
    talk3 = talkList.remove(0);
    talk4 = talkList.remove(0);

    setData(l1, talk1, R.drawable.material1);
    setData(l2, talk2, R.drawable.material2);
    setData(l3, talk3, R.drawable.material3);
    setData(l4, talk4, R.drawable.material4);

    rootView.findViewById(R.id.more).setOnClickListener(this);
    rootView.findViewById(R.id.card_view).setOnClickListener(this);

    return rootView;
}

From source file:com.actionbarsherlock.sample.demos.app.ActionBarActionItemCustomView.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, android.R.id.copy, 0, "Test");

    final int twentyDp = (int) (20 * getResources().getDisplayMetrics().density);

    TypedArray a = getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);
    final int abHeight = a.getLayoutDimension(R.styleable.SherlockTheme_abHeight, LayoutParams.FILL_PARENT);
    a.recycle();/*from  w  ww .j  a v  a  2  s  .  com*/

    LinearLayout l = new LinearLayout(this);
    l.setPadding(twentyDp, 0, twentyDp, 20);
    l.setBackgroundColor(0x55FF0000);

    TextView tv = new TextView(this);
    tv.setText("HI!!");
    tv.setGravity(Gravity.CENTER);
    tv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, abHeight));
    l.addView(tv);

    l.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(ActionBarActionItemCustomView.this, "Got custom action item click!",
                    Toast.LENGTH_SHORT).show();
        }
    });

    item.setActionView(l);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    return super.onCreateOptionsMenu(menu);
}