android.widget.ListView.setOnItemClickListener()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(272)

本文整理了Java中android.widget.ListView.setOnItemClickListener()方法的一些代码示例,展示了ListView.setOnItemClickListener()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ListView.setOnItemClickListener()方法的具体详情如下:
包路径:android.widget.ListView
类名称:ListView
方法名:setOnItemClickListener

ListView.setOnItemClickListener介绍

暂无

代码示例

代码示例来源:origin: CarGuo/GSYVideoPlayer

public void initList(List<SwitchVideoModel> data, OnListItemClickListener onItemClickListener) {
  this.onItemClickListener = onItemClickListener;
  this.data = data;
  LayoutInflater inflater = LayoutInflater.from(mContext);
  View view = inflater.inflate(R.layout.switch_video_dialog, null);
  listView = (ListView) view.findViewById(R.id.switch_dialog_list);
  setContentView(view);
  adapter = new ArrayAdapter<>(mContext, R.layout.switch_video_dialog_item, data);
  listView.setAdapter(adapter);
  listView.setOnItemClickListener(new OnItemClickListener());
  Window dialogWindow = getWindow();
  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
  DisplayMetrics d = mContext.getResources().getDisplayMetrics(); // 获取屏幕宽、高用
  lp.width = (int) (d.widthPixels * 0.8); // 高度设置为屏幕的0.6
  dialogWindow.setAttributes(lp);
}

代码示例来源:origin: orhanobut/dialogplus

@Override @NonNull
public View getView(@NonNull LayoutInflater inflater, ViewGroup parent) {
 View view = inflater.inflate(R.layout.dialog_list, parent, false);
 View outMostView = view.findViewById(R.id.dialogplus_outmost_container);
 outMostView.setBackgroundResource(backgroundResource);
 listView = view.findViewById(R.id.dialogplus_list);
 listView.setOnItemClickListener(this);
 listView.setOnKeyListener(new View.OnKeyListener() {
  @Override public boolean onKey(View v, int keyCode, KeyEvent event) {
   if (keyListener == null) {
    throw new NullPointerException("keyListener should not be null");
   }
   return keyListener.onKey(v, keyCode, event);
  }
 });
 headerContainer = view.findViewById(R.id.dialogplus_header_container);
 footerContainer = view.findViewById(R.id.dialogplus_footer_container);
 return view;
}

代码示例来源:origin: ankidroid/Anki-Android

private void createfieldLabels() {
  ArrayAdapter<String> mFieldLabelAdapter = new ArrayAdapter<>(this, R.layout.model_field_editor_list_item, mFieldLabels);
  mFieldLabelView.setAdapter(mFieldLabelAdapter);
  mFieldLabelView.setOnItemClickListener((parent, view, position, id) -> {
    mContextMenu = ModelEditorContextMenu.newInstance(mFieldLabels.get(position), mContextMenuListener);
    showDialogFragment(mContextMenu);
    mCurrentPos = position;
  });
}

代码示例来源:origin: smuyyh/BookReader

private void updateMark() {
  if (mMarkAdapter == null) {
    mMarkAdapter = new BookMarkAdapter(this, new ArrayList<BookMark>());
    lvMark.setAdapter(mMarkAdapter);
    lvMark.setOnItemClickListener(new AdapterView.OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        BookMark mark = mMarkAdapter.getData(position);
        if (mark != null) {
          mPageWidget.setPosition(new int[]{mark.chapter, mark.startPos, mark.endPos});
          hideReadBar();
        } else {
          ToastUtils.showSingleToast("书签无效");
        }
      }
    });
  }
  mMarkAdapter.clear();
  mMarkList = SettingManager.getInstance().getBookMarks(bookId);
  if (mMarkList != null && mMarkList.size() > 0) {
    Collections.reverse(mMarkList);
    mMarkAdapter.addAll(mMarkList);
  }
}

代码示例来源:origin: andyxialm/SmoothCheckBox

mList.add(new Bean());
lv.setAdapter(new BaseAdapter() {
  @Override
  public int getCount() {
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

代码示例来源:origin: stackoverflow.com

private void showDialog(){

  final Dialog dialog = new Dialog(this);

  View view = getLayoutInflater().inflate(R.layout.dialog_main, null);

  ListView lv = (ListView) view.findViewById(R.id.custom_list);

  // Change MyActivity.this and myListOfItems to your own values
  CustomListAdapterDialog clad = new CustomListAdapterDialog(MyActivity.this, myListOfItems);

  lv.setAdapter(clad);

  lv.setOnItemClickListener(........);

  dialog.setContentView(view);

  dialog.show();

}

代码示例来源:origin: square/picasso

@Override public View onCreateView(LayoutInflater inflater, ViewGroup container,
   Bundle savedInstanceState) {
  final SampleListDetailActivity activity = (SampleListDetailActivity) getActivity();
  final SampleListDetailAdapter adapter = new SampleListDetailAdapter(activity);
  ListView listView = (ListView) LayoutInflater.from(activity)
    .inflate(R.layout.sample_list_detail_list, container, false);
  listView.setAdapter(adapter);
  listView.setOnScrollListener(new SampleScrollListener(activity));
  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
   @Override
   public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
    String url = adapter.getItem(position);
    activity.showDetails(url);
   }
  });
  return listView;
 }
}

代码示例来源:origin: konmik/nucleus

@Override
public void onDestroyView() {
  super.onDestroyView();
  check1 = null;
  check2 = null;
  adapter = null;
  ((ListView)getView().findViewById(R.id.listView)).setOnItemClickListener(null);
}

代码示例来源:origin: google/ExoPlayer

private View buildSampleListView() {
 View dialogList = getLayoutInflater().inflate(R.layout.sample_list, null);
 ListView sampleList = dialogList.findViewById(R.id.sample_list);
 sampleList.setAdapter(new SampleListAdapter(this));
 sampleList.setOnItemClickListener(
   (parent, view, position, id) -> {
    playerManager.addItem(DemoUtil.SAMPLES.get(position));
    mediaQueueListAdapter.notifyItemInserted(playerManager.getMediaQueueSize() - 1);
   });
 return dialogList;
}

代码示例来源:origin: stackoverflow.com

final List<String> list = new ArrayList<String>();
list.add("Very long text AAAAAAAAAAAAAAAA");
list.add("1 Very long text AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
_lv.setAdapter(new ArrayAdapter<String>(getContext(), R.layout.simple_list_item_1, list));
_lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

代码示例来源:origin: fengjundev/Android-Skin-Loader

private void initView(View v) {
  titleBarLayout = (RelativeLayout) v.findViewById(R.id.title_bar_layout);
  newsList = (ListView) v.findViewById(R.id.news_list_view);
  adapter = new NewsAdapter(this.getActivity(), datas);
  newsList.setAdapter(adapter);
  newsList.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
  titleText = (TextView) v.findViewById(R.id.title_text);
  settingBtn = (Button) v.findViewById(R.id.title_bar_setting_btn);

代码示例来源:origin: facebook/facebook-android-sdk

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  ViewGroup view = (ViewGroup) inflater.inflate(layout, container, false);
  listView = (ListView) view.findViewById(R.id.com_facebook_picker_list_view);
  listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
      onListItemClick((ListView) parent, v, position);
    }
  });
  listView.setOnLongClickListener(new View.OnLongClickListener() {
    @Override
    public boolean onLongClick(View v) {
      // We don't actually do anything differently on long-clicks, but setting the listener
      // enables the selector transition that we have for visual consistency with the
      // Facebook app's pickers.
      return false;
    }
  });
  listView.setOnScrollListener(onScrollListener);
  activityCircle = (ProgressBar) view.findViewById(R.id.com_facebook_picker_activity_circle);
  setupViews(view);
  listView.setAdapter(adapter);
  return view;
}

代码示例来源:origin: stackoverflow.com

public class ListProductsFragment extends SherlockFragment {
private ListView list;

public static ListProductsFragment newInstance() {
  ListProductsFragment f = new ListProductsFragment();
  return f;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View V = inflater.inflate(R.layout.list, container, false);
  list = (ListView)V.findViewById(android.R.id.list);
  list.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
      int position, long id) {
     // This is important bit
     Fragment productDetailFragment = FragmentProductDetail.newInstance();
     FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
     transaction.addToBackStack(null);
     transaction.replace(R.id.products_list_linear, productDetailFragment).commit();
    }
   });       
  return V;
}
}

代码示例来源:origin: smuyyh/BookReader

@Override
public void initDatas() {
  key = getIntent().getStringExtra(INTENT_QUERY);
  mHisAdapter = new SearchHistoryAdapter(this, mHisList);
  lvSearchHistory.setAdapter(mHisAdapter);
  lvSearchHistory.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
      search(mHisList.get(position));
    }
  });
  initSearchHistory();
}

代码示例来源:origin: jeasonlzy/NineGridView

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  ButterKnife.bind(this);
  ArrayList<String> strings = new ArrayList<>();
  strings.add("使用RecyclerView展示news");
  strings.add("使用ListView展示Evaluation");
  ListView listView = (ListView) findViewById(R.id.listView);
  listView.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, strings));
  listView.setOnItemClickListener(this);
  frame.setOnCheckedChangeListener(this);
  frame.check(R.id.picasso);
}

代码示例来源:origin: ankidroid/Anki-Android

mCards = new ArrayList<>();
mCardsListView = (ListView) findViewById(R.id.card_browser_list);
    sflCustomFont);
mCardsListView.setAdapter(mCardsAdapter);
mCardsListView.setOnItemClickListener(new ListView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

代码示例来源:origin: jeasonlzy/ImagePicker

masker = view.findViewById(R.id.masker);
masker.setOnClickListener(this);
marginView = view.findViewById(R.id.margin);
marginView.setOnClickListener(this);
listView = (ListView) view.findViewById(R.id.listView);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {

代码示例来源:origin: aa112901/remusic

private void setUpDrawer() {
  LayoutInflater inflater = LayoutInflater.from(this);
  mLvLeftMenu.addHeaderView(inflater.inflate(R.layout.nav_header_main, mLvLeftMenu, false));
  mLvLeftMenu.setAdapter(new MenuItemAdapter(this));
  mLvLeftMenu.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

代码示例来源:origin: ogaclejapan/SmartTabLayout

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 ListView listView = (ListView) findViewById(R.id.list);
 listView.setOnItemClickListener(this);
 ArrayAdapter<String> demoAdapter = new ArrayAdapter<String>(this,
   android.R.layout.simple_list_item_1);
 for (Demo demo : Demo.values()) {
  demoAdapter.add(getString(demo.titleResId));
 }
 listView.setAdapter(demoAdapter);
}

代码示例来源:origin: stackoverflow.com

final ArrayList<String> values = new ArrayList<String>();
values.add("Android");
values.add("iPhone");
values.add("WindowsMobile");
values.add("Blackberry");
values.add("Windows7");
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
  @Override
  public void onItemClick(AdapterView<?> parent, View view,

相关文章

ListView类方法