Search in sources :

Example 6 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project android-app by eoecn.

the class MainActivity method initListView.

private void initListView() {
    lvAdapter = new SimpleAdapter(this, getData(), R.layout.behind_list_show, new String[] { LIST_TEXT, LIST_IMAGEVIEW }, new int[] { R.id.textview_behind_title, R.id.imageview_behind_icon }) {

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            // TODO Auto-generated method stub.
            View view = super.getView(position, convertView, parent);
            if (position == mTag) {
                view.setBackgroundResource(R.drawable.back_behind_list);
                lvTitle.setTag(view);
            } else {
                view.setBackgroundColor(Color.TRANSPARENT);
            }
            return view;
        }
    };
    lvTitle.setAdapter(lvAdapter);
    lvTitle.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            NavigationModel navModel = navs.get(position);
            mAboveTitle.setText(navModel.getName());
            current_page = navModel.getTags();
            if (lvTitle.getTag() != null) {
                if (lvTitle.getTag() == view) {
                    MainActivity.this.showContent();
                    return;
                }
                ((View) lvTitle.getTag()).setBackgroundColor(Color.TRANSPARENT);
            }
            lvTitle.setTag(view);
            view.setBackgroundResource(R.drawable.back_behind_list);
            imgQuery.setVisibility(View.VISIBLE);
            switch(position) {
                case 0:
                    imgQuery.setVisibility(View.GONE);
                    new MyTask().execute(topDao);
                    break;
                case 1:
                    new MyTask().execute(newsDao);
                    break;
                case 2:
                    new MyTask().execute(wikiDao);
                    break;
                case 3:
                    new MyTask().execute(blogsDao);
                    break;
            }
        }
    });
}
Also used : NavigationModel(cn.eoe.app.entity.NavigationModel) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) ViewGroup(android.view.ViewGroup) SimpleAdapter(android.widget.SimpleAdapter) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 7 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project SharedPreferenceInspector by PrashamTrivedi.

the class SharedPreferencesList method onViewCreated.

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    ListView lists = getListView();
    /**
		 * Get access to shared preferences list.
		 */
    File sharedPrefsDir = new File(getActivity().getApplicationInfo().dataDir, "shared_prefs");
    if (sharedPrefsDir.exists() && sharedPrefsDir.isDirectory()) {
        /**
			 * If exists and is directory, get the list.
			 */
        final String[] list = sharedPrefsDir.list();
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, android.R.id.text1, list);
        lists.setAdapter(adapter);
        setListAdapter(adapter);
        lists.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                String name = list[position];
                Bundle bundle = new Bundle();
                /**
					 * Remove .xml from the file name.
					 */
                String prefName = name.substring(0, name.length() - 4);
                bundle.putString("name", prefName);
                SharedPreferencesItem sharedPreferencesItem = SharedPreferencesItem.newInstance(bundle);
                ((SharedPrefsBrowser) getActivity()).startFragment(sharedPreferencesItem, "PreferencesList", true);
            }
        });
    } else {
        setListAdapter(null);
        setEmptyText("Nothing shared in stored preference");
    }
}
Also used : OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Bundle(android.os.Bundle) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) ListView(android.widget.ListView) File(java.io.File) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project Anki-Android by Ramblurr.

the class CardBrowser method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);
    View mainView = getLayoutInflater().inflate(R.layout.card_browser, null);
    setContentView(mainView);
    Themes.setContentStyle(mainView, Themes.CALLER_CARDBROWSER);
    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }
    mDeckNames = new HashMap<String, String>();
    for (long did : mCol.getDecks().allIds()) {
        mDeckNames.put(String.valueOf(did), mCol.getDecks().name(did));
    }
    registerExternalStorageListener();
    Intent i = getIntent();
    mWholeCollection = i.hasExtra("fromDeckpicker") && i.getBooleanExtra("fromDeckpicker", false);
    mBackground = Themes.getCardBrowserBackground();
    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());
    int sflRelativeFontSize = preferences.getInt("relativeCardBrowserFontSize", DEFAULT_FONT_SIZE_RATIO);
    String sflCustomFont = preferences.getString("browserEditorFont", "");
    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);
    Resources res = getResources();
    mOrderByFields = res.getStringArray(R.array.card_browser_order_labels);
    try {
        mOrder = CARD_ORDER_NONE;
        String colOrder = mCol.getConf().getString("sortType");
        for (int c = 0; c < fSortTypes.length; ++c) {
            if (fSortTypes[c].equals(colOrder)) {
                mOrder = c;
                break;
            }
        }
        if (mOrder == 1 && preferences.getBoolean("cardBrowserNoSorting", false)) {
            mOrder = 0;
        }
        mOrderAsc = Upgrade.upgradeJSONIfNecessary(mCol, mCol.getConf(), "sortBackwards", false);
        // default to descending for non-text fields
        if (fSortTypes[mOrder].equals("noteFld")) {
            mOrderAsc = !mOrderAsc;
        }
    } catch (JSONException e) {
        throw new RuntimeException(e);
    }
    mCards = new ArrayList<HashMap<String, String>>();
    mCardsListView = (ListView) findViewById(R.id.card_browser_list);
    mCardsAdapter = new SizeControlledListAdapter(this, mCards, R.layout.card_item, new String[] { "sfld", "deck", "flags" }, new int[] { R.id.card_sfld, R.id.card_deck, R.id.card_item }, sflRelativeFontSize, sflCustomFont);
    mCardsAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {

        @Override
        public boolean setViewValue(View view, Object arg1, String text) {
            if (view.getId() == R.id.card_item) {
                int which = BACKGROUND_NORMAL;
                if (text.equals("1")) {
                    which = BACKGROUND_SUSPENDED;
                } else if (text.equals("2")) {
                    which = BACKGROUND_MARKED;
                } else if (text.equals("3")) {
                    which = BACKGROUND_MARKED_SUSPENDED;
                }
                view.setBackgroundResource(mBackground[which]);
                return true;
            } else if (view.getId() == R.id.card_deck && text.length() > 0) {
                view.setVisibility(View.VISIBLE);
            }
            return false;
        }
    });
    mCardsListView.setAdapter(mCardsAdapter);
    mCardsListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mPositionInCardsList = position;
            long cardId = Long.parseLong(mCards.get(mPositionInCardsList).get("id"));
            sCardBrowserCard = mCol.getCard(cardId);
            Intent editCard = new Intent(CardBrowser.this, CardEditor.class);
            editCard.putExtra(CardEditor.EXTRA_CALLER, CardEditor.CALLER_CARDBROWSER_EDIT);
            editCard.putExtra(CardEditor.EXTRA_CARD_ID, sCardBrowserCard.getId());
            startActivityForResult(editCard, EDIT_CARD);
            if (AnkiDroidApp.SDK_VERSION > 4) {
                ActivityTransitionAnimation.slide(CardBrowser.this, ActivityTransitionAnimation.LEFT);
            }
        }
    });
    registerForContextMenu(mCardsListView);
    mSearchEditText = (EditText) findViewById(R.id.card_browser_search);
    mSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                onSearch();
                return true;
            }
            return false;
        }
    });
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    mSearchButton = (ImageButton) findViewById(R.id.card_browser_search_button);
    mSearchButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onSearch();
        }
    });
    mSearchTerms = "";
    if (mWholeCollection) {
        mRestrictOnDeck = "";
        setTitle(res.getString(R.string.card_browser_all_decks));
    } else {
        try {
            String deckName = mCol.getDecks().current().getString("name");
            mRestrictOnDeck = "deck:'" + deckName + "' ";
            setTitle(deckName);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }
    }
    mSelectedTags = new HashSet<String>();
    if (!preferences.getBoolean("cardBrowserNoSearchOnOpen", false)) {
        searchCards();
    }
}
Also used : HashMap(java.util.HashMap) KeyEvent(android.view.KeyEvent) TextView(android.widget.TextView) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) SharedPreferences(android.content.SharedPreferences) JSONException(org.json.JSONException) SimpleAdapter(android.widget.SimpleAdapter) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) Resources(android.content.res.Resources)

Example 9 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project StickerCamera by Skykai521.

the class AlbumFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreateView(inflater, container, savedInstanceState);
    View root = inflater.inflate(R.layout.fragment_album, null);
    photos = (ArrayList<PhotoItem>) getArguments().getSerializable("photos");
    albums = (GridView) root.findViewById(R.id.albums);
    albums.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            PhotoItem photo = photos.get(arg2);
            CameraManager.getInst().processPhotoItem(getActivity(), photo);
        }
    });
    return root;
}
Also used : PhotoItem(com.stickercamera.app.model.PhotoItem) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView)

Example 10 with OnItemClickListener

use of android.widget.AdapterView.OnItemClickListener in project GT by Tencent.

the class GTLogSearchActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gt_log_search_activity);
    handler = new Handler();
    tv_count = (TextView) findViewById(R.id.log_search_count);
    btn_pre = (ImageButton) findViewById(R.id.log_msg_pre);
    btn_next = (ImageButton) findViewById(R.id.log_msg_next);
    /*
		 * 用于覆盖整个屏幕的透明ImageView,
		 * 主要帮助点击非filterListView区域使filterListView消失
		 */
    img_empty = (ImageView) findViewById(R.id.log_search_view_empty);
    img_empty.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    img_empty.setVisibility(View.GONE);
                    filterListView.setVisibility(View.GONE);
                    cancelFilterMsgInput(v);
                    break;
                case MotionEvent.ACTION_UP:
                    v.performClick();
                    break;
                default:
                    break;
            }
            return false;
        }
    });
    // 过滤数据展示列表
    filterListView = (ListView) findViewById(R.id.log_search_spinner_list);
    //		filterLock = new ReentrantLock();
    filterListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View v, int position, long arg3) {
            img_empty.setVisibility(View.GONE);
            filterListView.setVisibility(View.GONE);
            String sCurSelectedMsg = (String) parent.getAdapter().getItem(position);
            LinkedList<String> curShowDownMsgList = GTLogInternal.getCurShowDownMsgList();
            LinkedList<String> msgHistory = GTLogInternal.getCurSearchMsgHistory();
            GTLogInternal.setCurSearchMsg(sCurSelectedMsg);
            msgWatched = false;
            et_Msg.removeTextChangedListener(msg_watcher);
            String s = curShowDownMsgList.remove(position);
            curShowDownMsgList.addFirst(s);
            msgHistory.remove(s);
            msgHistory.addFirst(s);
            et_Msg.setText(sCurSelectedMsg);
            btn_msg_clear.setVisibility(View.VISIBLE);
            cancelFilterMsgInput(parent);
            //				filterLock.lock();
            ((MsgAdaptor) filterListView.getAdapter()).getFilter().filter(sCurSelectedMsg);
            //				filterLock.unlock();
            doSearch(sCurSelectedMsg);
        }
    });
    // 过滤文本
    et_Msg = (EditText) findViewById(R.id.log_search_msg);
    //		et_Msg.setText(BHLog.getCurSearchMsg());
    et_Msg.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!msgWatched) {
                et_Msg.addTextChangedListener(msg_watcher);
                msgWatched = true;
            }
            MsgAdaptor adapter = new MsgAdaptor(GTLogSearchActivity.this);
            adapter.getFilter().filter(et_Msg.getText().toString());
            //				filterLock.lock();
            filterListView.setAdapter(adapter);
            //				filterLock.unlock();
            if (!filterListView.getAdapter().isEmpty()) {
                filterListView.setVisibility(View.VISIBLE);
                img_empty.setVisibility(View.VISIBLE);
            }
        }
    });
    et_Msg.setOnKeyListener(new View.OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            switch(keyCode) {
                case KeyEvent.KEYCODE_ENTER:
                    // 要先把过滤showdown去掉,否则会多弹出一次
                    msgWatched = false;
                    et_Msg.removeTextChangedListener(msg_watcher);
                    String word = et_Msg.getText().toString();
                    filterListView.setVisibility(View.GONE);
                    img_empty.setVisibility(View.GONE);
                    cancelFilterMsgInput(v);
                    if (word.trim().length() == 0) {
                        return true;
                    }
                    LinkedList<String> curShowDownMsgList = GTLogInternal.getCurShowDownMsgList();
                    LinkedList<String> msgHistory = GTLogInternal.getCurSearchMsgHistory();
                    msgHistory.remove(word);
                    msgHistory.addFirst(word);
                    curShowDownMsgList.remove(word);
                    curShowDownMsgList.addFirst(word);
                    doSearch(word);
                    return true;
            }
            return false;
        }
    });
    // 过滤文本的清理
    btn_msg_clear = (ImageButton) findViewById(R.id.log_msg_search_clear);
    btn_msg_clear.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            et_Msg.setText("");
            // 清理本次搜索标记
            GTLogInternal.clearLastSearchMarks();
            tv_count.setText("0 / 0");
            arrayAdapter.notifyDataSetChanged();
            btn_msg_clear.setVisibility(View.GONE);
        }
    });
    // 改成back功能了
    btn_back = (Button) findViewById(R.id.log_msg_search_cancel);
    btn_back.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // 20130404 改成back功能了
            finish();
        }
    });
    btn_pre.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int historySeq = GTLogInternal.getLastMatchedSeq();
            if (historySeq > 0) {
                GTLogInternal.setLastMatchedSeq(historySeq - 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(historySeq - 1).posionInDataSet);
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                historySeq + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            } else if (historySeq == 0 && GTLogInternal.getLastMatchedEntryList().size() > 0) {
                GTLogInternal.setLastMatchedSeq(GTLogInternal.getLastMatchedEntryList().size() - 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(GTLogInternal.getLastMatchedEntryList().size() - 1).posionInDataSet);
                tv_count.setText(GTLogInternal.getLastMatchedEntryList().size() + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            }
        }
    });
    btn_next.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            int historySeq = GTLogInternal.getLastMatchedSeq();
            if (historySeq < GTLogInternal.getLastMatchedEntryList().size() - 1) {
                GTLogInternal.setLastMatchedSeq(historySeq + 1);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(historySeq + 1).posionInDataSet);
                int viewSeq = historySeq + 2;
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                viewSeq + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            } else if (historySeq == GTLogInternal.getLastMatchedEntryList().size() - 1) {
                GTLogInternal.setLastMatchedSeq(0);
                listView.setSelection(GTLogInternal.getLastMatchedEntryList().get(0).posionInDataSet);
                tv_count.setText(// 这里注意显示序号要比存储位置多1,因为从1开始算
                1 + " / " + GTLogInternal.getLastMatchedEntryList().size());
                handler.post(new Runnable() {

                    @Override
                    public void run() {
                        // 这个刷新需要在UI线程排队,否则会被listView.setSelection方法冲突掉
                        arrayAdapter.notifyDataSetChanged();
                    }
                });
            }
        }
    });
    // 准备日志列表数据
    listView = (ListView) findViewById(R.id.log_search_list);
    Intent intent = getIntent();
    String openFileName = intent.getStringExtra("openFileName");
    if (openFileName == null) {
        // 日志列表
        dataSet = GTLogInternal.getCurFilteredLogs();
        arrayAdapter = new SearchLogAdapter(this, dataSet);
        listView.setAdapter(arrayAdapter);
    } else // 打开历史日志
    {
        openLog(openFileName);
    }
}
Also used : SearchLogAdapter(com.tencent.wstt.gt.log.SearchLogAdapter) OnTouchListener(android.view.View.OnTouchListener) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) Handler(android.os.Handler) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) LinkedList(java.util.LinkedList) MotionEvent(android.view.MotionEvent) KeyEvent(android.view.KeyEvent) OnClickListener(android.view.View.OnClickListener)

Aggregations

OnItemClickListener (android.widget.AdapterView.OnItemClickListener)135 AdapterView (android.widget.AdapterView)134 View (android.view.View)133 ListView (android.widget.ListView)102 TextView (android.widget.TextView)71 Intent (android.content.Intent)43 ImageView (android.widget.ImageView)41 OnClickListener (android.view.View.OnClickListener)24 Bundle (android.os.Bundle)18 ArrayAdapter (android.widget.ArrayAdapter)17 SuppressLint (android.annotation.SuppressLint)15 Paint (android.graphics.Paint)12 ColorDrawable (android.graphics.drawable.ColorDrawable)11 GridView (android.widget.GridView)11 LayoutInflater (android.view.LayoutInflater)10 DialogInterface (android.content.DialogInterface)9 CheckBox (android.widget.CheckBox)9 LinearLayout (android.widget.LinearLayout)9 ArrayList (java.util.ArrayList)7 OnItemLongClickListener (android.widget.AdapterView.OnItemLongClickListener)6