當前位置: 首頁>>代碼示例>>Java>>正文


Java ListView類代碼示例

本文整理匯總了Java中android.widget.ListView的典型用法代碼示例。如果您正苦於以下問題:Java ListView類的具體用法?Java ListView怎麽用?Java ListView使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ListView類屬於android.widget包,在下文中一共展示了ListView類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updatePodcastRows

import android.widget.ListView; //導入依賴的package包/類
private void updatePodcastRows() {
    ListView list = getListView();
    int first = list.getFirstVisiblePosition();
    int last = list.getLastVisiblePosition();
    for (int i = first; i <= last; i++) {
        View view = list.getChildAt(i - first);
        list.getAdapter().getView(i, view, list);
    }
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:10,代碼來源:PodcastsActivity.java

示例2: setListItemLongClick

import android.widget.ListView; //導入依賴的package包/類
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;
        }
    });
}
 
開發者ID:Kaufland,項目名稱:andcouchbaseentity,代碼行數:20,代碼來源:TaskActivity.java

示例3: actionModeDelete

import android.widget.ListView; //導入依賴的package包/類
private void actionModeDelete() {
    ListView lv = getListView();
    
    ArrayList<Long> checkedIds = new ArrayList<Long>();
    
    for(int i = 0; i < lv.getCount(); i++) {
        if(lv.isItemChecked(i)) {
            long[] selectedIds = mAdapter.getCallIdsAtPosition(i);
            
            for(long id : selectedIds) {
                checkedIds.add(id);
            }
            
        }
    }
    if(checkedIds.size() > 0) {
        String strCheckedIds = TextUtils.join(", ", checkedIds);
        Log.d(THIS_FILE, "Checked positions ("+ strCheckedIds +")");
        getActivity().getContentResolver().delete(SipManager.CALLLOG_URI, Calls._ID + " IN ("+strCheckedIds+")", null);
        mMode.finish();
    }
}
 
開發者ID:treasure-lau,項目名稱:CSipSimple,代碼行數:23,代碼來源:CallLogListFragment.java

示例4: setCharacterList

import android.widget.ListView; //導入依賴的package包/類
private void setCharacterList(){

        ListView character_list = (ListView) findViewById(R.id.character_list);
        final ArrayAdapter<Character> adapter = new RowAdapter(this,characters);
        character_list.setAdapter(adapter);

        character_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

                boolean isSelected = characters.get(i).isActive() ? false : true;
                characters.get(i).setActive(isSelected);
                adapter.notifyDataSetChanged();

            }
        });

    }
 
開發者ID:jleon95,項目名稱:LearnHangul,代碼行數:19,代碼來源:CharactersActivity.java

示例5: onCreate

import android.widget.ListView; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.habit_list);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    IOManager.initManager(getApplicationContext());
    lv = (ListView) findViewById(R.id.listOfUserHabits);
    addHabitBtn = (ImageButton) findViewById(R.id.addNewHabit);
    try {
        HabitListController.initHabitList();
        HabitListController.getHabitList().addObserver(this);
    } catch (NetworkUnavailableException e){
        Toast.makeText(this, "You must be connected to a network" +
                " to view, edit, and add habits.", Toast.LENGTH_LONG).show();
        finish();
    }
    initListeners();
}
 
開發者ID:CMPUT301F17T23,項目名稱:routineKeen,代碼行數:19,代碼來源:HabitListActivity.java

示例6: onListItemClick

import android.widget.ListView; //導入依賴的package包/類
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    if (((GlobalValues) getActivity().getApplication()).CanCreateVariable()) {
        Matrix m = ((GlobalValues) getActivity().getApplication()).GetCompleteList().get(position);
        Matrix clone;
        clone = m.ExactClone("Copy_" + m.GetName());
        ((GlobalValues) getActivity().getApplication()).GetCompleteList().add(clone);
        ((GlobalValues) getActivity().getApplication()).matrixAdapter.notifyDataSetChanged();
        Toast.makeText(getContext(), "Saved as Copy_" + m.GetName(), Toast.LENGTH_SHORT).show();
        NavigationView view = (NavigationView) getActivity().findViewById(R.id.nav_view);
        view.setCheckedItem(R.id.Home);
        FragmentTransaction transaction = getActivity().getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.MainContent, new MainActivityFragmentList());
        transaction.commit();
        ((MainActivity) getActivity()).SetMainActivity(true, getString(R.string.app_name), getString(R.string.MainSubtitle));
    } else {
        if (!((GlobalValues) getActivity().getApplication()).AdLoaded)
            Toast.makeText(getContext(), R.string.ToAddMoreTurnData, Toast.LENGTH_SHORT).show();
        else
            Toast.makeText(getContext(), R.string.LimitExceeds, Toast.LENGTH_SHORT).show();
    }


}
 
開發者ID:coder3101,項目名稱:Matrix-Calculator-for-Android,代碼行數:25,代碼來源:CloneFragment.java

示例7: testEdit

import android.widget.ListView; //導入依賴的package包/類
/**
 * Test to make sure the edit button actually modifies the event
 */
public void testEdit(){

    if (((ListView)solo.getView(R.id.historyList)).getAdapter().getCount() > 0){
        solo.clickInList(1, 0);
        solo.sleep(2000);
        solo.assertCurrentActivity("wrong activity", HabitEventViewActivity.class);
        solo.clearEditText(0);
        solo.sleep(600);
        solo.enterText(0, "newcomment");
        solo.sleep(600);
        solo.clickOnButton("Save");
        solo.sleep(2000);
        solo.assertCurrentActivity("wrong activity", HistoryActivity.class);
        solo.clickInList(1, 0);
        solo.sleep(3000);
        solo.assertCurrentActivity("wrong activity", HabitEventViewActivity.class);
        // make sure the comment was changed
        assertTrue(((EditText)solo.getView(R.id.vheCommentDynamicText)).getText().toString().equals("newcomment"));

    }
}
 
開發者ID:CMPUT301F17T15,項目名稱:CIA,代碼行數:25,代碼來源:ViewHabitEventIntentTests.java

示例8: initViews

import android.widget.ListView; //導入依賴的package包/類
private void initViews() {
    DialogAdapter dialogAdapter=new DialogAdapter(mName);
    ListView dialogList=(ListView) findViewById(R.id.dialog_list);
    Button mMBtnCancel = (Button) findViewById(R.id.mBtn_Cancel);
    TextView mTvTitle = (TextView) findViewById(R.id.mTv_Title);

    dialogList.setOnItemClickListener(this);
    dialogList.setAdapter(dialogAdapter);
    mMBtnCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if(mCancelListener != null){
                mCancelListener.onCancelClick(v);
            }
            dismiss();
        }
    });

    if(!TextUtils.isEmpty(mTitle)){
        mTvTitle.setVisibility(View.VISIBLE);
        mTvTitle.setText(mTitle);
    }else{
        mTvTitle.setVisibility(View.GONE);
    }
}
 
開發者ID:yangchong211,項目名稱:YCDialog,代碼行數:26,代碼來源:CustomSelectDialog.java

示例9: init

import android.widget.ListView; //導入依賴的package包/類
private void init(Context context, AttributeSet attrs) {
    this.context = context;
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.EaseContactList);
    primaryColor = ta.getColor(R.styleable.EaseContactList_ctsListPrimaryTextColor, 0);
    primarySize = ta.getDimensionPixelSize(R.styleable.EaseContactList_ctsListPrimaryTextSize, 0);
    showSiderBar = ta.getBoolean(R.styleable.EaseContactList_ctsListShowSiderBar, true);
    initialLetterBg = ta.getDrawable(R.styleable.EaseContactList_ctsListInitialLetterBg);
    initialLetterColor = ta.getColor(R.styleable.EaseContactList_ctsListInitialLetterColor, 0);
    ta.recycle();


    LayoutInflater.from(context).inflate(R.layout.ease_widget_contact_list, this);
    listView = (ListView) findViewById(R.id.list);
    sidebar = (EaseSidebar) findViewById(R.id.sidebar);
    if (!showSiderBar)
        sidebar.setVisibility(View.GONE);
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:18,代碼來源:ContactList.java

示例10: onKeyDown

import android.widget.ListView; //導入依賴的package包/類
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // Shortcuts that work no matter what is selected
    if (QMail.useVolumeKeysForListNavigationEnabled() &&
            (keyCode == KeyEvent.KEYCODE_VOLUME_UP ||
            keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {

        final ListView listView = getListView();

        int currentPosition = listView.getSelectedItemPosition();
        if (currentPosition == AdapterView.INVALID_POSITION || listView.isInTouchMode()) {
            currentPosition = listView.getFirstVisiblePosition();
        }

        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && currentPosition > 0) {
            listView.setSelection(currentPosition - 1);
        } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN &&
                currentPosition < listView.getCount()) {
            listView.setSelection(currentPosition + 1);
        }

        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:27,代碼來源:K9ListActivity.java

示例11: onCreateView

import android.widget.ListView; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_settings, container, false);

    // Inflate chess.com logo
    View header = inflater.inflate(R.layout.list_settings_header, null);
    header.setOnClickListener(mHeaderClickListener);

    // Init ListView
    mListView = (ListView) v.findViewById(R.id.list_time_controls);
    mListView.addHeaderView(header, null, false);
    mListView.setOnItemClickListener(mItemClickListener);

    // Set start button listener
    mStartBtn = v.findViewById(R.id.btn_start);
    mStartBtn.setOnClickListener(mStartBtnListener);

    // Set List Adapter and selection positions.
    setupListView(savedInstanceState);

    return v;
}
 
開發者ID:ChessCom,項目名稱:android-chessclock,代碼行數:23,代碼來源:SettingsFragment.java

示例12: onCreate

import android.widget.ListView; //導入依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    android.content.Intent intent = getIntent();

    beverageName = intent.getStringExtra(beverageNameKey);
    beverageVolume = intent.getDoubleExtra(beverageVolumeKey, 0.0);
    beverageAlcoholicStrength = intent.getDoubleExtra(beverageAlcoholicKey, 0.0);

    bartour = Bartout.getInstance().getActiveBartour();
    users = bartour.getUsers();

    editTextBeverageName = (EditText) findViewById(R.id.editTextBeverageName);
    editTextBeverageVolume = (EditText) findViewById(R.id.editTextBeverageVolume);
    editTextAlcoholicStrength = (EditText) findViewById(R.id.editTextBeverageAlcoholicStrength);

    editTextBeverageName.setText(beverageName);
    editTextBeverageVolume.setText(Double.toString(beverageVolume));
    editTextAlcoholicStrength.setText(Double.toString(beverageAlcoholicStrength));

    listViewUsers = (ListView) findViewById(R.id.listViewDrinkUsers);

    UserBeverageAdapter userBeverageAdapter = new UserBeverageAdapter(this, users);
    listViewUsers.setAdapter(userBeverageAdapter);

}
 
開發者ID:Bartout-Team,項目名稱:Bartout,代碼行數:27,代碼來源:DrinkBeverageActivity.java

示例13: setListViewHeightBasedOnChildren

import android.widget.ListView; //導入依賴的package包/類
/***
 * 動態設置listview的高度
 * 
 * @param listView
 */
public void setListViewHeightBasedOnChildren(ListView listView) {
	ListAdapter listAdapter = listView.getAdapter();
	if (listAdapter == null) {
		return;
	}
	int totalHeight = 0;
	for (int i = 0; i < listAdapter.getCount(); i++) {
		View listItem = listAdapter.getView(i, null, listView);
		listItem.measure(0, 0);
		totalHeight += listItem.getMeasuredHeight();
	}
	ViewGroup.LayoutParams params = listView.getLayoutParams();
	params.height = totalHeight
			+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
	// params.height += 5;// if without this statement,the listview will be
	// a
	// little short
	// listView.getDividerHeight()獲取子項間分隔符占用的高度
	// params.height最後得到整個ListView完整顯示需要的高度
	listView.setLayoutParams(params);
}
 
開發者ID:qizhenghao,項目名稱:HiBangClient,代碼行數:27,代碼來源:EditProvinceActivity.java

示例14: onLoadFinished

import android.widget.ListView; //導入依賴的package包/類
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in.  (The framework will take care of closing the
    // old cursor once we return.)
    lAdapter.swapCursor(data);
    getListView().postDelayed(new Runnable() {
        @Override
        public void run() {
            ListView lv = getListView();
            if(selecting) {
                if (selectedLabelId == -1L){
                    // Set headerview as checked
                    lv.setItemChecked(0, true);
                } else {
                    lv.setItemChecked(getAdapterItemPosition(selectedLabelId) + lv.getHeaderViewsCount(), true);
                }
            }
        }
    }, 100);

}
 
開發者ID:danlls,項目名稱:Todule-android,代碼行數:22,代碼來源:ToduleLabelFragment.java

示例15: onCreateView

import android.widget.ListView; //導入依賴的package包/類
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  listView = (ListView) inflater.inflate(R.layout.venstremenu_frag, container, false);
  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      venstremenuAdapter.vælgMenu(getActivity(), position);
    }
  });
  venstremenuAdapter = new VenstremenuAdapter(getActivity());
  listView.setAdapter(venstremenuAdapter);
  listView.setItemChecked(mCurrentSelectedPosition, true);
  for (Backend b : App.backend) b.favoritter.observatører.add(this);
  App.data.hentedeUdsendelser.observatører.add(this);
  Alarms.setNextAlert(getActivity());
  return listView;
}
 
開發者ID:nordfalk,項目名稱:EsperantoRadio,代碼行數:18,代碼來源:Venstremenu_frag.java


注:本文中的android.widget.ListView類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。