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

The following are Jave code examples for showing how to use setOnItemLongClickListener() 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: andcouchbaseentity   File: TaskActivity.java   View Source Code Vote up 7 votes
private void setListItemLongClick(ListView listView) {
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int pos, long id) {
            PopupMenu popup = new PopupMenu(TaskActivity.this, view);
            popup.inflate(R.menu.task_item);
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    TaskEntity task = (TaskEntity) mAdapter.getItem(pos - 1);
                    handleTaskPopupAction(item, task);
                    return true;
                }
            });
            popup.show();
            return true;
        }
    });
}
 
Example 2
Project: stynico   File: buff_ext.java   View Source Code Vote up 6 votes
@Override
   protected void onCreate(Bundle savedInstanceState)
   {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_buff);
StatusBarUtil.setColor(this, getResources().getColor(R.color.colorPrimary));
       apkPathText = (TextView) findViewById(R.id.apkPathText);
apitils.KEY = "";//初始化
// 初始化控件
lv = (ListView) findViewById(R.id.lv_main);
adapter = new apiAdapter(this);
adapter.setList(list);
adapter.setUninstall(buff_ext.this);// 传入接口
lv.setAdapter(adapter);
lv.setOnItemClickListener(buff_ext.this);
lv.setOnItemLongClickListener(buff_ext.this);
sort = (TextView) findViewById(R.id.sort);
count = (TextView) findViewById(R.id.count);
size = (TextView) findViewById(R.id.size);
iv_asc = (ImageView) findViewById(R.id.iv_asc);
//img = (ImageView) findViewById(R.id.img3);
// donghua();
updateData();// 子线程--拿数据
   }
 
Example 3
Project: yyox   File: FeedBackDetailsActivity.java   View Source Code Vote up 6 votes
@Override
protected void initWidgets() {
    super.initWidgets();
    mLayoutBottom = (RelativeLayout) findViewById(R.id.kf5_bottom_layout);
    mFeedBackDetailBottomView = new FeedBackDetailBottomView(mActivity);
    mFeedBackDetailBottomView.setListener(this);
    mETContent = layoutListener.getEditText();
    mLayoutBottom.addView(mFeedBackDetailBottomView);
    mListView = (ListView) findViewById(R.id.kf5_activity_feed_back_details_listview);
    mListView.setOnScrollListener(this);
    mListView.setOnItemLongClickListener(this);
    mListView.addHeaderView(inflateHeaderView());
    mBackImg = (ImageView) findViewById(R.id.kf5_return_img);
    mBackImg.setOnClickListener(this);
    mRightView = (TextView) findViewById(R.id.kf5_right_text_view);
    mRightView.setOnClickListener(this);
}
 
Example 4
Project: android-apps   File: TodoFragment.java   View Source Code Vote up 6 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  View view = inflater.inflate(R.layout.fragment_todo, container, false);
  toolbar = (Toolbar) view.findViewById(R.id.toolbar);
  toolbar.setTitle(getString(R.string.title_todo));
  toolbar.inflateMenu(R.menu.todo);
  toolbar.setOnMenuItemClickListener(this);

  listView = (ListView) view.findViewById(R.id.list_view);
  refreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.refresh_layout);
  adapter = new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, localTodoData);
  listView.setAdapter(adapter);
  listView.setOnItemLongClickListener(this);
  refreshLayout.setOnRefreshListener(this);

  return view;
}
 
Example 5
Project: privacyidea-authenticator   File: MainActivity.java   View Source Code Vote up 6 votes
private void setupViews() {
    setTitle(AppConstants.APP_TITLE);
    setContentView(R.layout.activity_main);
    listview = (ListView) findViewById(R.id.listview);
    listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
            nextSelection = tokenlist.get(i);
            startSupportActionMode(MainActivity.this);
            return true;
        }
    });
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(getResources().getColor(PIBLUE));
    if (getSupportActionBar() != null) {
        getSupportActionBar().setLogo(R.mipmap.ic_launcher);
        getSupportActionBar().setDisplayUseLogoEnabled(true);
    }
}
 
Example 6
Project: TrainPonctuality   File: ShowHistoryActivity.java   View Source Code Vote up 6 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle(R.string.titleHistory);

    //noinspection ConstantConditions
    getSupportActionBar().setBackgroundDrawable(new ColorDrawable(ContextCompat.getColor(this, R.color.historyHeader)));

    //Bundle extras = getIntent().getExtras();
    setContentView(R.layout.activity_show_list);

    try (TravelDAO dbTravel = new TravelDAO(this)) {
        data = dbTravel.selectHistory();
    }

    adapter = new HistoryAdapter(this, R.layout.show_history_row, data);
    ListView listView1 = (ListView) findViewById(R.id.listView1);
    listView1.setAdapter(adapter);
    listView1.setOnItemLongClickListener(this);
    listView1.setOnItemClickListener(this);
}
 
Example 7
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 8
Project: easyfilemanager   File: ConnectionsFragment.java   View Source Code Vote up 5 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    final Resources res = getActivity().getResources();

    fab = (FloatingActionButton)view.findViewById(R.id.fab);
    fab.setOnClickListener(this);
    if(isTelevision()){
        fab.setVisibility(View.GONE);
    }

    mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);
    mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);
    mListView = (ListView) view.findViewById(R.id.list);
    mListView.setOnItemClickListener(mItemListener);
    if(isTelevision()) {
        mListView.setOnItemLongClickListener(mItemLongClickListener);
    }
    fab.attachToListView(mListView);

    // Indent our list divider to align with text
    final Drawable divider = mListView.getDivider();
    final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
    final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
    if (insetLeft) {
        mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
    } else {
        mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
    }
}
 
Example 9
Project: Sortable_tableview_soussidev   File: TableView.java   View Source Code Vote up 5 votes
private void setupTableDataView(final AttributeSet attributes, final int styleAttributes) {
    final LayoutParams dataViewLayoutParams = new LayoutParams(getWidthAttribute(attributes), LayoutParams.MATCH_PARENT);

    if (isInEditMode()) {
        tableDataAdapter = new EditModeTableDataAdapter(getContext());
    } else {
        tableDataAdapter = new DefaultTableDataAdapter(getContext());
    }
    tableDataAdapter.setRowBackgroundProvider(dataRowBackgroundProvider);

    tableDataView = new ListView(getContext(), attributes, styleAttributes);

    tableDataView.setOnItemClickListener(new InternalDataClickListener());
    tableDataView.setOnItemLongClickListener(new InternalDataLongClickListener());
    tableDataView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tableDataView.setAdapter(tableDataAdapter);
    tableDataView.setId(R.id.table_data_view);
    tableDataView.setOnScrollListener(new InternalOnScrollListener());

    swipeRefreshLayout = new SwipeRefreshLayout(getContext());
    swipeRefreshLayout.setLayoutParams(dataViewLayoutParams);
    swipeRefreshLayout.addView(tableDataView);
    swipeRefreshLayout.setColorSchemeColors(headerColor);
    swipeRefreshLayout.setEnabled(false);

    addView(swipeRefreshLayout);
}
 
Example 10
Project: Mingnote   File: MainActivity.java   View Source Code Vote up 5 votes
private void InitView() {
    listView = (ListView) findViewById(R.id.listview);
    dataList = new ArrayList<Map<String, Object>>();//映射条目
    fab_editnote = (FloatingActionButton) findViewById(R.id.fab_editnote);
    DbHelper = new Database(this);
    DB = DbHelper.getReadableDatabase();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        //沉浸状态栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //沉浸导航栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
    }

    listView.setOnItemClickListener(this);
    listView.setOnItemLongClickListener(this);

    fab_editnote.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent(MainActivity.this, NoteEdit.class);
            Bundle bundle = new Bundle();
            bundle.putString("info", "");
            bundle.putInt("enter_state", 0);
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });
}
 
Example 11
Project: FireFiles   File: ConnectionsFragment.java   View Source Code Vote up 5 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    final Resources res = getActivity().getResources();

    fab = (FloatingActionButton)view.findViewById(R.id.fab);
    fab.setOnClickListener(this);
    if(isTelevision()){
        fab.setVisibility(View.GONE);
    }

    mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);
    mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);
    mListView = (ListView) view.findViewById(R.id.list);
    mListView.setOnItemClickListener(mItemListener);
    if(isTelevision()) {
        mListView.setOnItemLongClickListener(mItemLongClickListener);
    }
    fab.attachToListView(mListView);

    // Indent our list divider to align with text
    final Drawable divider = mListView.getDivider();
    final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
    final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
    if (insetLeft) {
        mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
    } else {
        mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
    }
}
 
Example 12
Project: simple-share-android   File: ConnectionsFragment.java   View Source Code Vote up 5 votes
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    final Resources res = getActivity().getResources();

    fab = (FloatingActionButton)view.findViewById(R.id.fab);
    fab.setOnClickListener(this);
    if(isTelevision()){
        fab.setVisibility(View.GONE);
    }

    mProgressBar = (MaterialProgressBar) view.findViewById(R.id.progressBar);
    mEmptyView = (CompatTextView)view.findViewById(android.R.id.empty);
    mListView = (ListView) view.findViewById(R.id.list);
    mListView.setOnItemClickListener(mItemListener);
    if(isTelevision()) {
        mListView.setOnItemLongClickListener(mItemLongClickListener);
    }
    fab.attachToListView(mListView);

    // Indent our list divider to align with text
    final Drawable divider = mListView.getDivider();
    final boolean insetLeft = res.getBoolean(R.bool.list_divider_inset_left);
    final int insetSize = res.getDimensionPixelSize(R.dimen.list_divider_inset);
    if (insetLeft) {
        mListView.setDivider(new InsetDrawable(divider, insetSize, 0, 0, 0));
    } else {
        mListView.setDivider(new InsetDrawable(divider, 0, 0, insetSize, 0));
    }
}
 
Example 13
Project: sctalk   File: ChatFragment.java   View Source Code Vote up 5 votes
private void initContactListView() {
    contactListView = (ListView) curView.findViewById(R.id.ContactListView);
    contactListView.setOnItemClickListener(this);
    contactListView.setOnItemLongClickListener(this);
    contactAdapter = new  ChatAdapter(getActivity());
    contactListView.setAdapter(contactAdapter);

    // this is critical, disable loading when finger sliding, otherwise
    // you'll find sliding is not very smooth
    contactListView.setOnScrollListener(new PauseOnScrollListener(ImageLoader.getInstance(),
            true, true));
}
 
Example 14
Project: ArscEditor   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	// 设置主界面布局文件
	setContentView(R.layout.string_list);
	// 初始化列表控件
	stringListView = (ListView) findViewById(R.id.list_res_string);
	// 初始化显示资源类型的文本框
	textCategory = (TextView) findViewById(R.id.textCategory);
	// 初始化显示资源Config的文本框
	textConfig = (TextView) findViewById(R.id.textConfig);
	// 初始化翻译按钮
	btnTranslate = (ImageView) findViewById(R.id.btnTranslate);
	// 初始化搜索按钮
	btnSearch = (ImageView) findViewById(R.id.btnSearch);
	// 初始化保存按钮
	btnSave = (ImageView) findViewById(R.id.btnSave);
	// 获取用来显示信息的文本框
	info = (TextView) findViewById(R.id.info);
	// 为显示资源类型的文本框设置点击事件的监听器
	textCategory.setOnClickListener(MyOnClickListener);
	// 为显示资源Config的文本框设置点击事件的监听器
	textConfig.setOnClickListener(MyOnClickListener);
	// 为显示资源类型的文本框设置文本内容改变的监听器
	textCategory.addTextChangedListener(textWatcher);
	// 为显示资源Config的文本框设置文本内容改变的监听器
	textConfig.addTextChangedListener(textWatcher);
	// 为翻译按钮设置点击事件监听器
	btnTranslate.setOnClickListener(MyOnClickListener);
	// 为搜索按钮设置点击事件监听器
	btnSearch.setOnClickListener(MyOnClickListener);
	// 为保存按钮设置点击事件监听器
	btnSave.setOnClickListener(MyOnClickListener);
	// 初始化数据适配器
	mAdapter = new stringListAdapter(this);
	// 为列表控件设置数据适配器
	stringListView.setAdapter(mAdapter);
	// 为列表控件设置长按事件监听器
	stringListView.setOnItemLongClickListener(this);
	try {
		open("/sdcard/resources.arsc");
	} catch (IOException e) {
		showMessage(this, e.toString()).show();
	}
}
 
Example 15
Project: Misc   File: AppDetailsActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Get the preferences
    SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(this);
    Gson gson = new Gson();
    String json = prefs.getString(PREF_APPDETAILS_APP_NAMES, "");
    String[] appNames = gson.fromJson(json, String[].class);
    createAppDetailsFromAppNames(appNames);

    // Handle long click in the ListView
    final ListView lv = getListView();
    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener
            () {
        @Override
        public boolean onItemLongClick(AdapterView<?> av, View view,
                                       final int pos, long id) {
            final CharSequence[] items = {
                    getText(R.string.app_details_edit),
                    getText(R.string.app_details_delete),
                    getText(R.string.app_details_add),
                    getText(R.string.app_details_move_up),
                    getText(R.string.app_details_move_down),
            };
            AlertDialog.Builder builder =
                    new AlertDialog.Builder(AppDetailsActivity.this);
            builder.setTitle(getText(R.string.app_details_modify));
            builder.setSingleChoiceItems(items, 0,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int
                                item) {
                            dialog.dismiss();
                            switch (item) {
                                case 0:
                                    editItem(pos);
                                    break;
                                case 1:
                                    deleteItem(pos);
                                    break;
                                case 2:
                                    addItem(pos);
                                    break;
                                case 3:
                                    moveItemUp(pos);
                                    break;
                                case 4:
                                    moveItemDown(pos);
                                    break;
                            }
                        }
                    });
            AlertDialog alert = builder.create();
            alert.show();
            // Need to return true or it will call the onClickListener
            return true;
        }
    });
}
 
Example 16
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
//            }
//        }
    }
 
Example 17
Project: RestaurantApp   File: DeskBasketActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.AppThemeStaffLogin);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_desk_basket);

    lvBasket= (ListView) findViewById(R.id.lvBasket);
    lvBasket.setOnItemLongClickListener(this);
    lvBasket.setOnItemClickListener(this);
    productList = new ArrayList<>();

    btnOrderVerify = (FlatButton) findViewById(R.id.btnOrderVerify);
    btnOrderVerify.setOnClickListener(this);

    getSupportActionBar().setDisplayOptions(android.support.v7.app.ActionBar.DISPLAY_SHOW_CUSTOM);
    getSupportActionBar().setCustomView(R.layout.custom_actionbar);
    tvActionBar = (TextView)getSupportActionBar().getCustomView().findViewById(R.id.tvActionBar);
    tvActionBar.setText(getResources().getString(R.string.staffDeskBasketHeader));
    tvActionBar.setTextAppearance(this, android.R.style.TextAppearance_Large);
    tvActionBar.setTextColor(Color.WHITE);

    orderId = getIntent().getIntExtra("orderId",-1);
    status = getIntent().getIntExtra("status",-1);
    url+=orderId;

    if (status == 0){
        btnOrderVerify.setBackgroundColor(getResources().getColor(R.color.status0));
        btnOrderVerify.setText("SİPARİŞ YOK");
        btnOrderVerify.setClickable(false);
    }else if (status == 1){
        btnOrderVerify.setBackgroundColor(getResources().getColor(R.color.status1));
        btnOrderVerify.setText("SİPARİŞİ ONAYLA");
        btnOrderVerify.setClickable(true);
    }else{
        btnOrderVerify.setBackgroundColor(getResources().getColor(R.color.status2));
        btnOrderVerify.setText("SİPARİŞ ONAYLANMIŞ");
        btnOrderVerify.setClickable(false);
    }

    Request request = new Request(this, url, com.android.volley.Request.Method.GET);
    request.requestVolleyDeskList(this);

}
 
Example 18
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 19
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
//            }
//        }
    }