Java Code Examples for android.widget.ListView.setChoiceMode()

The following are Jave code examples for showing how to use setChoiceMode() of the android.widget.ListView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: q-mail   File: RecipientSelectView.java   View Source Code Vote up 6 votes
public void showAlternatesPopup(List<Recipient> data) {
    if (loaderManager == null) {
        return;
    }

    // Copy anchor settings from the autocomplete dropdown
    View anchorView = getRootView().findViewById(getDropDownAnchor());
    alternatesPopup.setAnchorView(anchorView);
    alternatesPopup.setWidth(getDropDownWidth());

    alternatesAdapter.setCurrentRecipient(alternatesPopupRecipient);
    alternatesAdapter.setAlternateRecipientInfo(data);

    // Clear the checked item.
    alternatesPopup.show();
    ListView listView = alternatesPopup.getListView();
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
 
Example 2
Project: CSipSimple   File: ConversationsListFragment.java   View Source Code Vote up 6 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // View management
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);

    // Modify list view
    ListView lv = getListView();
    lv.setVerticalFadingEdgeEnabled(true);
    // lv.setCacheColorHint(android.R.color.transparent);
    if (mDualPane) {
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setItemsCanFocus(false);
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }
}
 
Example 3
Project: CSipSimple   File: FavListFragment.java   View Source Code Vote up 6 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // View management
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);

    // Modify list view
    ListView lv = getListView();
    lv.setVerticalFadingEdgeEnabled(true);
    // lv.setCacheColorHint(android.R.color.transparent);
    if (mDualPane) {
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setItemsCanFocus(false);
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }
}
 
Example 4
Project: Quran   File: TagBookmarkDialog.java   View Source Code Vote up 6 votes
private ListView createTagsListView() {
  final FragmentActivity activity = getActivity();

  mAdapter = new TagsAdapter(activity, mTagBookmarkPresenter);

  final ListView listview = new ListView(activity);
  listview.setAdapter(mAdapter);
  listview.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
  listview.setOnItemClickListener((parent, view, position, id) -> {
    Tag tag = (Tag) mAdapter.getItem(position);
    boolean isChecked = mTagBookmarkPresenter.toggleTag(tag.id);

    Object viewTag = view.getTag();
    if (viewTag instanceof ViewHolder) {
      ViewHolder holder = (ViewHolder) viewTag;
      holder.checkBox.setChecked(isChecked);
    }
  });
  return listview;
}
 
Example 5
Project: MainCalendar   File: FilePicker.java   View Source Code Vote up 6 votes
@Override
@NonNull
protected LinearLayout makeCenterView() {
    LinearLayout rootLayout = new LinearLayout(activity);
    rootLayout.setLayoutParams(new LinearLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    rootLayout.setBackgroundColor(Color.WHITE);
    rootLayout.setOrientation(LinearLayout.VERTICAL);
    ListView listView = new ListView(activity);
    listView.setBackgroundColor(Color.WHITE);
    listView.setDivider(new ColorDrawable(0xFFDDDDDD));
    listView.setDividerHeight(1);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    listView.setSelector(R.color.itemSelected);
    listView.setCacheColorHint(Color.TRANSPARENT);
    listView.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT));
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
    rootLayout.addView(listView);
    return rootLayout;
}
 
Example 6
Project: GravityBox   File: LocationTileSlimkat.java   View Source Code Vote up 6 votes
@Override
public View createDetailView(Context context, View convertView, ViewGroup parent) throws Throwable {
    if (mDetails == null) {
        mDetails = QsDetailItemsList.create(context, parent);
        mDetails.setEmptyState(R.drawable.ic_qs_location_off,
                GpsStatusMonitor.getModeLabel(mContext, Settings.Secure.LOCATION_MODE_OFF));
        mAdapter = new AdvancedLocationAdapter(context);
        mDetails.setAdapter(mAdapter);
    
        final ListView list = mDetails.getListView();
        list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        list.setOnItemClickListener(this);
    }

    return mDetails.getView();
}
 
Example 7
Project: CIA   File: TodaysHabitsFragment.java   View Source Code Vote up 5 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    user = (Profile) getArguments().getSerializable(ID_PROFILE);
    todaysHabits = user.getTodaysHabits();
    noTasks = (TextView) view.findViewById(R.id.noTasks);

    if (todaysHabits.size() > 0) {
        noTasks.setVisibility(View.GONE);
    }

    // today's tasks listview (checkable)
    checkable = (ListView) view.findViewById(R.id.TodayToDoListView);
    checkable.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
    resetCheckableListAdapter();
}
 
Example 8
Project: QuizApp   File: SingleChoiceFragment.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_quiz_page, container, false);

    View headerview = ((LayoutInflater) getActivity().getApplicationContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE))
            .inflate(R.layout.item_list_header_view, null, false);
    ((TextView) headerview.findViewById(android.R.id.title)).setText(mPage.getQuestionText());




    final ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    listView.addHeaderView(headerview);

    setListAdapter(new ArrayAdapter<String>(getActivity(),
            R.layout.item_answer,
            android.R.id.text1,
            mChoices));
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    // Pre-select currently selected item.
    new Handler().post(new Runnable() {
        @Override
        public void run() {
            String selection = mPage.getData().getString(QuizPage.DATA_KEY);
            for (int i = 0; i < mChoices.size(); i++) {
                if (mChoices.get(i).equals(selection)) {
                    listView.setItemChecked(i+1, true); // a simple hack
                    break;
                }
            }
        }
    });

    return rootView;
}
 
Example 9
Project: QuizApp   File: ReviewFragment.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_quiz_review, container, false);

    TextView titleView = (TextView) rootView.findViewById(android.R.id.title);
    titleView.setText("Review");
    titleView.setTextColor(getResources().getColor(R.color.review_title));

    ListView listView = (ListView) rootView.findViewById(android.R.id.list);
    mReviewAdapter = new ReviewAdapter(mReviewList, getContext());
    setListAdapter(mReviewAdapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    return rootView;
}
 
Example 10
Project: godlibrary   File: FragmentListView.java   View Source Code Vote up 5 votes
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_list_view, container, false);
    listView = (ListView) v.findViewById(R.id.listView);
    listView.setChoiceMode(mChoiceMode);
    initView();
    return v;
}
 
Example 11
Project: GravityBox   File: RingerModeTile.java   View Source Code Vote up 5 votes
@Override
public View createDetailView(Context context, View convertView, ViewGroup parent) throws Throwable {
    if (mDetails == null) {
        mDetails = QsDetailItemsList.create(context, parent);
        mDetails.setEmptyState(0, null);
        mAdapter = new ModeAdapter(context);
        mDetails.setAdapter(mAdapter);
    
        final ListView list = mDetails.getListView();
        list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        list.setOnItemClickListener(this);
    }

    return mDetails.getView();
}
 
Example 12
Project: CSipSimple   File: CallLogListFragment.java   View Source Code Vote up 5 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // View management
    mDualPane = getResources().getBoolean(R.bool.use_dual_panes);


    // Modify list view
    ListView lv = getListView();
    lv.setVerticalFadingEdgeEnabled(true);
    // lv.setCacheColorHint(android.R.color.transparent);
    if (mDualPane) {
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        lv.setItemsCanFocus(false);
    } else {
        lv.setChoiceMode(ListView.CHOICE_MODE_NONE);
        lv.setItemsCanFocus(true);
    }
    
    // Map long press
    lv.setLongClickable(true);
    lv.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> ad, View v, int pos, long id) {
            turnOnActionMode();
            getListView().setItemChecked(pos, true);
            mMode.invalidate();
            return true;
        }
    });
}
 
Example 13
Project: custode   File: ContactsPickerActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_contacts_picker);
    listView = (ListView) findViewById(R.id.list_view);
    listView.setOnItemClickListener(this);
    listView.setChoiceMode(AbsListView.CHOICE_MODE_NONE);

    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED)
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_CONTACTS}, 0);
    else
        loadData();
}
 
Example 14
Project: CSipSimple   File: AccountFiltersListFragment.java   View Source Code Vote up 5 votes
@Override 
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    ListView lv = getListView();

    //getListView().setSelector(R.drawable.transparent);
    lv.setCacheColorHint(Color.TRANSPARENT);
    
    
    // View management
    View detailsFrame = getActivity().findViewById(R.id.details);
    dualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;
    

    if (savedInstanceState != null) {
        // Restore last state for checked position.
        curCheckFilterId = savedInstanceState.getLong(CURRENT_CHOICE, SipProfile.INVALID_ID);
        //curCheckWizard = savedInstanceState.getString(CURRENT_WIZARD);
    }
    setListShown(false);
    if(mAdapter == null) {
        if(mHeaderView != null) {
            lv.addHeaderView(mHeaderView , null, true);
        }
        mAdapter = new AccountFiltersListAdapter(getActivity(), null);
        //getListView().setEmptyView(getActivity().findViewById(R.id.progress_container));
        //getActivity().findViewById(android.R.id.empty).setVisibility(View.GONE);
        setListAdapter(mAdapter);
        registerForContextMenu(lv);

        
        lv.setVerticalFadingEdgeEnabled(true);
    }
    
    if (dualPane) {
        // In dual-pane mode, the list view highlights the selected item.
    	Log.d("lp", "dual pane mode");
        lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    	//lv.setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_LEFT);
        lv.setVerticalScrollBarEnabled(false);
        lv.setFadingEdgeLength(50);
        
        updateCheckedItem();
        // Make sure our UI is in the correct state.
        //showDetails(curCheckPosition, curCheckWizard);
    }else {
    	//getListView().setVerticalScrollbarPosition(View.SCROLLBAR_POSITION_RIGHT);
    	lv.setVerticalScrollBarEnabled(true);
    	lv.setFadingEdgeLength(100);
    }
}
 
Example 15
Project: Todule-android   File: ToduleLabelFragment.java   View Source Code Vote up 5 votes
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    lAdapter = new LabelAdapter(getActivity(), null, 0);
    setListAdapter(lAdapter);
    getActivity().getSupportLoaderManager().initLoader(LOADER_ID, null, this);
    myActivity = (MainActivity) getActivity();
    myActivity.getSupportActionBar().setTitle("Labels");
    myActivity.hideSoftKeyboard(true);
    myActivity.fabVisibility(false);

    ListView listView = getListView();

    if(selecting){
        setActivateOnItemClick(true);
        myActivity.getSupportActionBar().setTitle("Select label");
        // Add "no label" to list
        View noLabel =  View.inflate(getContext(), R.layout.fragment_label_item, null);
        TextView labelTag = noLabel.findViewById(R.id.label_tag);
        labelTag.setText(R.string.none);
        listView.addHeaderView(noLabel);
    } else {
        listView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL);
        listView.setMultiChoiceModeListener(myMultiChoiceModeListener);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                ToduleLabelAddFragment f = ToduleLabelAddFragment.newInstance(l);
                myActivity.getSupportFragmentManager().beginTransaction()
                        .setCustomAnimations(R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right)
                        .replace(R.id.fragment_container, f)
                        .addToBackStack(null)
                        .commit();
            }
        });
    }
}
 
Example 16
Project: GravityBox   File: NetworkModeTile.java   View Source Code Vote up 5 votes
@Override
public View createDetailView(Context context, View convertView, ViewGroup parent) throws Throwable {
    if (mDetails == null) {
        mDetails = QsDetailItemsList.create(context, parent);
        mDetails.setEmptyState(0, null);
        mAdapter = new ModeAdapter(context);
        mDetails.setAdapter(mAdapter);
    
        final ListView list = mDetails.getListView();
        list.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
        list.setOnItemClickListener(this);
    }

    return mDetails.getView();
}
 
Example 17
Project: backup   File: CreateBackupActivityController.java   View Source Code Vote up 5 votes
void populatePackageList(ListView packageListView, CreateBackupActivity parent) {
    List<String> eligiblePackageList = new LinkedList<>();
    try {
        eligiblePackageList.addAll(backupManager.getEligiblePackages());

    } catch (RemoteException e) {
        Log.e(TAG, "Error while obtaining package list: ", e);
    }

    packageListView.setOnItemClickListener(parent);
    packageListView.setAdapter(new ArrayAdapter<>(parent, R.layout.checked_list_item, eligiblePackageList));
    packageListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
 
Example 18
Project: container   File: ResolverActivity.java   View Source Code Vote up 4 votes
protected void onCreate(Bundle savedInstanceState, Intent intent,
                            CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList,
                            boolean alwaysUseOption,int userid) {
        super.onCreate(savedInstanceState);
        mLaunchedFromUid = userid;
        mPm = getPackageManager();
        mAlwaysUseOption = alwaysUseOption;
        mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns);

        mRegistered = true;

        final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        mIconDpi = am.getLauncherLargeIconDensity();
        mIconSize = am.getLauncherLargeIconSize();

        mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList,
                mLaunchedFromUid);
        int count = mAdapter.getCount();
        if (Build.VERSION.SDK_INT >= 17) {
            if (mLaunchedFromUid < 0) {
                // Gulp!
                finish();
                return;
            }
        }

        if (count == 1) {
            startSelected(0, false);
            mRegistered = false;
            finish();
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        if (count > 1) {
            mListView = new ListView(this);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(this);
            mListView.setOnItemLongClickListener(new ItemLongClickListener());
            builder.setView(mListView);
            if (alwaysUseOption) {
                mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            }
        } else {
            builder.setMessage(R.string.noApplications);
        }
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog = builder.show();
//
//        if (alwaysUseOption) {
//            final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
//            if (buttonLayout != null) {
//                buttonLayout.setVisibility(View.VISIBLE);
//                mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
//                mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
//            } else {
//                mAlwaysUseOption = false;
//            }
//            // Set the initial highlight if there was a preferred or last used choice
//            final int initialHighlight = mAdapter.getInitialHighlight();
//            if (initialHighlight >= 0) {
//                mListView.setItemChecked(initialHighlight, true);
//                onItemClick(null, null, initialHighlight, 0); // Other entries are not used
//            }
//        }
    }
 
Example 19
Project: TPlayer   File: ResolverActivity.java   View Source Code Vote up 4 votes
protected void onCreate(Bundle savedInstanceState, Intent intent,
                            CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList,
                            boolean alwaysUseOption, int userid) {
        super.onCreate(savedInstanceState);
        mLaunchedFromUid = userid;
        mPm = getPackageManager();
        mAlwaysUseOption = alwaysUseOption;
        mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns);

        mRegistered = true;

        final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        mIconDpi = am.getLauncherLargeIconDensity();
        mIconSize = am.getLauncherLargeIconSize();

        mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList,
                mLaunchedFromUid);
        int count = mAdapter.getCount();
        if (Build.VERSION.SDK_INT >= 17) {
            if (mLaunchedFromUid < 0) {
                // Gulp!
                finish();
                return;
            }
        }

        if (count == 1) {
            startSelected(0, false);
            mRegistered = false;
            finish();
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        if (count > 1) {
            mListView = new ListView(this);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(this);
            mListView.setOnItemLongClickListener(new ItemLongClickListener());
            builder.setView(mListView);
            if (alwaysUseOption) {
                mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            }
        } else {
            builder.setMessage(R.string.noApplications);
        }
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog = builder.show();
//
//        if (alwaysUseOption) {
//            final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
//            if (buttonLayout != null) {
//                buttonLayout.setVisibility(View.VISIBLE);
//                mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
//                mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
//            } else {
//                mAlwaysUseOption = false;
//            }
//            // Set the initial highlight if there was a preferred or last used choice
//            final int initialHighlight = mAdapter.getInitialHighlight();
//            if (initialHighlight >= 0) {
//                mListView.setItemChecked(initialHighlight, true);
//                onItemClick(null, null, initialHighlight, 0); // Other entries are not used
//            }
//        }
    }
 
Example 20
Project: VirtualHook   File: ResolverActivity.java   View Source Code Vote up 4 votes
protected void onCreate(Bundle savedInstanceState, Intent intent,
                            CharSequence title, Intent[] initialIntents, List<ResolveInfo> rList,
                            boolean alwaysUseOption, int userid) {
        super.onCreate(savedInstanceState);
        mLaunchedFromUid = userid;
        mPm = getPackageManager();
        mAlwaysUseOption = alwaysUseOption;
        mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns);

        mRegistered = true;

        final ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
        mIconDpi = am.getLauncherLargeIconDensity();
        mIconSize = am.getLauncherLargeIconSize();

        mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList,
                mLaunchedFromUid);
        int count = mAdapter.getCount();
        if (Build.VERSION.SDK_INT >= 17) {
            if (mLaunchedFromUid < 0) {
                // Gulp!
                finish();
                return;
            }
        }

        if (count == 1) {
            startSelected(0, false);
            mRegistered = false;
            finish();
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(title);
        if (count > 1) {
            mListView = new ListView(this);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(this);
            mListView.setOnItemLongClickListener(new ItemLongClickListener());
            builder.setView(mListView);
            if (alwaysUseOption) {
                mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            }
        } else {
            builder.setMessage(R.string.noApplications);
        }
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        dialog = builder.show();
//
//        if (alwaysUseOption) {
//            final ViewGroup buttonLayout = (ViewGroup) findViewById(R.id.button_bar);
//            if (buttonLayout != null) {
//                buttonLayout.setVisibility(View.VISIBLE);
//                mAlwaysButton = (Button) buttonLayout.findViewById(R.id.button_always);
//                mOnceButton = (Button) buttonLayout.findViewById(R.id.button_once);
//            } else {
//                mAlwaysUseOption = false;
//            }
//            // Set the initial highlight if there was a preferred or last used choice
//            final int initialHighlight = mAdapter.getInitialHighlight();
//            if (initialHighlight >= 0) {
//                mListView.setItemChecked(initialHighlight, true);
//                onItemClick(null, null, initialHighlight, 0); // Other entries are not used
//            }
//        }
    }