Java Code Examples for android.widget.ListView#setOnItemClickListener()

The following examples show how to use android.widget.ListView#setOnItemClickListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CircularFloatingActivity.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.circular_floating_menu_fragment_demo, container, false);

    String[] items = { "Menu with FloatingActionButton",
                       "Menu attached to custom button",
                       "Menu with custom animation",
                       "Menu in ScrollView"
                    };
    ArrayAdapter<String> simpleAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
    demosListView = (ListView) rootView.findViewById(R.id.demosListView);
    demosListView.setAdapter(simpleAdapter);
    demosListView.setOnItemClickListener(this);
    return rootView;
}
 
Example 2
Source File: AddAliasView.java    From Atomic with GNU General Public License v3.0 6 votes vote down vote up
public AddAliasView(Context context, ArrayList<String> aliases) {
  super(context);
  this.aliases = (ArrayList<String>)(aliases.clone());

  LayoutInflater.from(context).inflate(R.layout.aliasadd, this, true);

  aliasInput = (EditText)findViewById(R.id.alias);
  aliasInput.addTextChangedListener(this);

  adapter = new ArrayAdapter<String>(this.getContext(), R.layout.aliasitem, this.aliases);

  ListView list = (ListView)findViewById(R.id.aliases);
  list.setAdapter(adapter);
  list.setOnItemClickListener(this);

  addButton = (Button)findViewById(R.id.add);
  addButton.setOnClickListener(this);
}
 
Example 3
Source File: FragmentListActivity.java    From android-discourse with Apache License 2.0 6 votes vote down vote up
/**
 * Updates the screen state (current list and other views) when the content
 * changes.
 *
 * @see Activity#onContentChanged()
 */
@Override
public void onContentChanged() {
    super.onContentChanged();

    // changed references from com.android.internal.R to android.R.*
    View emptyView = findViewById(android.R.id.empty);
    mList = (ListView) findViewById(android.R.id.list);

    if (mList == null) {
        throw new RuntimeException("Your content must have a ListView whose id attribute is " + "'android.R.id.list'");
    }
    if (emptyView != null) {
        mList.setEmptyView(emptyView);
    }
    mList.setOnItemClickListener(mOnClickListener);
    if (mFinishedStart) {
        setListAdapter(mAdapter);
    }
    mHandler.post(mRequestFocus);
    mFinishedStart = true;
}
 
Example 4
Source File: SampleClickSliderViewActivity.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_clicksilderview);
    sliderView = (ClickSliderView) findViewById(R.id.slider_view);
    Button button1 = (Button) findViewById(R.id.button1);
    Button button2 = (Button) findViewById(R.id.button2);
    button1.setOnClickListener(this);
    button2.setOnClickListener(this);
    listView = (ListView) findViewById(R.id.listView);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, new String[] { "GOOD",
                    "HAHA", "What is that?", "FUUUUCK" });
    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
}
 
Example 5
Source File: CHMActivity.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle("List bookmarks");
        setContentView(R.layout.dialog_bookmark);
        setCanceledOnTouchOutside(true);
        setCancelable(true);
        add = (Button) findViewById(R.id.btn_addbookmark);
        add.setOnClickListener(this);
        listView = (ListView) findViewById(R.id.listView);
        adapter = new ArrayAdapter<String>(mainActivity, android.R.layout.simple_list_item_1, listBookmark);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
	@Override
	public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
		webview.loadUrl("file://" + extractPath + "/" + listBookmark.get(i));
		dismiss();
	}
});
    }
 
Example 6
Source File: MainActivity.java    From Folding-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);
	setContentView(R.layout.activity_main);

	ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
			android.R.layout.simple_list_item_1, testValues);
	listView = (ListView) findViewById(R.id.listView1);
	listView.setAdapter(adapter);
	listView.setOnItemClickListener(new OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			Intent intent = new Intent();
			intent.setClassName("com.ptr.folding.sample","com.ptr.folding.sample."+testValues[arg2]
				+ "Activity");

			startActivity(intent);

		}
	});

}
 
Example 7
Source File: ExchangeDialogFragment.java    From android with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle args = getArguments();
    final int titleResId = args.getInt(FRAGMENT_BUNDLE_KEY_TITLE_RES_ID);
    final int optionsResId = args.getInt(FRAGMENT_BUNDLE_KEY_OPTIONS_RES_ID);
    final String message = args.getString(FRAGMENT_BUNDLE_KEY_MESSAGE);

    final String[] options = getResources().getStringArray(optionsResId);

    MaterialDialog dialog = new MaterialDialog.Builder(getActivity())
            .title(titleResId)
            .adapter(new ArrayAdapter<>(getActivity(), R.layout.view_exchange_item, options), null)
            .build();

    ListView listView = dialog.getListView();
    if (listView != null) {
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // TODO
                String text = options[position] + "\n" + message;
                Toast.makeText(getActivity(), text, Toast.LENGTH_SHORT).show();

                ExchangeDialogFragment.this.dismiss();
            }
        });
    }

    return dialog;
}
 
Example 8
Source File: LinksDialogFragment.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_dialog_links, container, false);
    getDialog().setTitle(R.string.post_links_title);
    ListView lv = (ListView) view.findViewById(R.id.links_list_view);
    lv.setAdapter(new LinksAdapter(inflater));
    lv.setOnItemClickListener(this);
    return view;
}
 
Example 9
Source File: ChooserActivity.java    From endpoints-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_chooser);

    // Set up ListView and Adapter
    ListView listView = (ListView) findViewById(R.id.list_view);

    MyArrayAdapter adapter = new MyArrayAdapter(this, android.R.layout.simple_list_item_2, CLASSES);
    adapter.setDescriptionIds(DESCRIPTION_IDS);

    listView.setAdapter(adapter);
    listView.setOnItemClickListener(this);
}
 
Example 10
Source File: StatusSubscribeActivity.java    From YiBo with Apache License 2.0 5 votes vote down vote up
private void bindEvent() {
	Button btnBack = (Button)this.findViewById(R.id.btnBack);
	btnBack.setOnClickListener(new GoBackClickListener());

	Button btnOperate = (Button) this.findViewById(R.id.btnOperate);
	btnOperate.setVisibility(View.VISIBLE);
	btnOperate.setText(R.string.btn_home);
	btnOperate.setOnClickListener(new GoHomeClickListener());

	ListView lvMicroBlog = (ListView)this.findViewById(R.id.lvMicroBlog);
	lvMicroBlog.setOnItemClickListener(new MicroBlogItemClickListener(this));
	MicroBlogContextMenuListener contextMenuListener =
		new MicroBlogContextMenuListener(lvMicroBlog);
	lvMicroBlog.setOnCreateContextMenuListener(contextMenuListener);
}
 
Example 11
Source File: ContentActivity.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
private void initView() {
	mTitleView = (TextView) findViewById(R.id.dev_name_tv);
	mProgressBarPreparing = (ProgressBar) findViewById(R.id.player_prepairing);
	mContentLv = (ListView) findViewById(R.id.content_list);
	mContentAdapter = new ContentAdapter(ContentActivity.this, mContentList);
	mContentLv.setAdapter(mContentAdapter);
	mContentLv.setOnItemClickListener(contentItemClickListener);
}
 
Example 12
Source File: DoubleListView.java    From DropDownMenu with Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    setOrientation(VERTICAL);
    inflate(context, R.layout.merge_filter_list, this);

    lv_left = (ListView) findViewById(R.id.lv_left);
    lv_right = (ListView) findViewById(R.id.lv_right);
    lv_left.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    lv_right.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    lv_left.setOnItemClickListener(this);
    lv_right.setOnItemClickListener(this);
}
 
Example 13
Source File: History.java    From EBookDownloader with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
    setContentView(R.layout.activity_history);

    try {
        historyDB = DBFactory.open(getApplicationContext(), "history");
    } catch (SnappydbException e) {
        e.printStackTrace();
    }

    ListView listHistory = findViewById(R.id.list_history);
    history = new ArrayList<>();

    fillHistoryList();

    arrayAdapter = new ArrayAdapter<>(this, R.layout.listview_list_item,
            history);
    listHistory.setAdapter(arrayAdapter);
    listHistory.setOnItemLongClickListener(this);
    listHistory.setOnItemClickListener(this);

    if (history.isEmpty()) {
        showNoHistory();
    }
}
 
Example 14
Source File: MainActivity.java    From listmyaps with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle b) {
	super.onCreate(b);
	requestWindowFeature(Window.FEATURE_PROGRESS);
	setContentView(R.layout.activity_main);
	ListView listView = getListView();
	listView.setOnItemClickListener(this);
	listView.setOnItemLongClickListener(this);
	AppRater.appLaunched(this);
}
 
Example 15
Source File: RileyLinkBLEScanActivity.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.rileylink_scan_activity);

    // Initializes Bluetooth adapter.
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
    mHandler = new Handler();

    mLeDeviceListAdapter = new LeDeviceListAdapter();
    listBTScan = (ListView) findViewById(R.id.rileylink_listBTScan);
    listBTScan.setAdapter(mLeDeviceListAdapter);
    listBTScan.setOnItemClickListener((parent, view, position, id) -> {

        // stop scanning if still active
        if (mScanning) {
            mScanning = false;
            mLEScanner.stopScan(mScanCallback2);
        }

        TextView textview = (TextView) view.findViewById(R.id.rileylink_device_address);
        String bleAddress = textview.getText().toString();

        SP.putString(RileyLinkConst.Prefs.RileyLinkAddress, bleAddress);

        RileyLinkUtil.getRileyLinkSelectPreference().setSummary(bleAddress);

        MedtronicPumpStatus pumpStatus = MedtronicUtil.getPumpStatus();
        pumpStatus.verifyConfiguration(); // force reloading of address

        RxBus.INSTANCE.send(new EventMedtronicPumpConfigurationChanged());

        finish();
    });

    toolbarBTScan = (Toolbar) findViewById(R.id.rileylink_toolbarBTScan);
    toolbarBTScan.setTitle(R.string.rileylink_scanner_title);
    setSupportActionBar(toolbarBTScan);

    prepareForScanning();
}
 
Example 16
Source File: ItemEditActivity.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_expense_edit);

    View statusBar = findViewById(R.id.status_bar);
    //设置模拟状态栏的高度
    ViewGroup.LayoutParams layoutParams = statusBar.getLayoutParams();
    layoutParams.height = ScreenUtil.getStatusBarHeight(this);
    statusBar.setLayoutParams(layoutParams);

    listView = (ListView) findViewById(R.id.aiee_list);
    dao = AccountItemDao.getInstance();
    intent = getIntent();
    if (intent != null) {
        type = intent.getIntExtra(TYPE, 0);
        if (type == SUB_EXPENSE) {
            long itemId = intent.getLongExtra("id", 0);
            if (itemId > 0)
                parent = dao.findItemById(itemId);
        }
    }

    String title = "";
    switch (type) {
        case EXPENSE:
            title = "支出项目类别-编辑";
            items = dao.findAllByExpense(1);
            break;
        case SUB_EXPENSE:
            title = parent.getItem() + "子类别-编辑";
            subItems = dao.findAllByItemid(parent.getId());
            break;
        case INCOME:
            title = "收入项目类别-编辑";
            items = dao.findAllByExpense(0);
            break;
    }
    ((TextView) findViewById(R.id.aiee_title)).setText(title);
    inflater = LayoutInflater.from(this);
    listView.setAdapter(adapter);
    findViewById(R.id.aiee_back).setOnClickListener(clickListener);
    findViewById(R.id.aiee_finish).setOnClickListener(clickListener);
    findViewById(R.id.aiee_add).setOnClickListener(clickListener);
    if (type == 0) {
        listView.setOnItemClickListener(itemListener);
    }

}
 
Example 17
Source File: DropdownSpinner.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
private void showPopup()
{
	if (mAdapter != null && mAdapter.getCount() > 0)
	{
		try
		{
			ListView lv = new ListView(getContext());
			lv.setAdapter(mAdapter);
			lv.setOnItemClickListener(this);
			lv.setDivider(mDivider);
			
			Rect rectGlobal = new Rect();
			this.getGlobalVisibleRect(rectGlobal);

			Rect rectGlobalParent = new Rect();
			((View) this.getParent()).getGlobalVisibleRect(rectGlobalParent);

			int maxHeight = rectGlobalParent.bottom - rectGlobal.top;
			lv.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST));

			mPopup = new PopupWindow(lv, getWidth(), lv.getMeasuredHeight(), true);
			mPopup.setOutsideTouchable(true);
			mPopup.setBackgroundDrawable(mDropDownBackground);
			mPopup.showAtLocation(this, Gravity.TOP | Gravity.LEFT, rectGlobal.left, rectGlobal.top);
			mPopup.getContentView().setOnClickListener(new View.OnClickListener()
			{
				@Override
				public void onClick(View v)
				{
					mPopup.dismiss();
					mPopup = null;
				}
			});
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}
}
 
Example 18
Source File: CalendarFragment.java    From prayer-times-android with Apache License 2.0 4 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.calendar_frag, container, false);

    ListView listView = view.findViewById(android.R.id.list);

    year = getArguments().getInt(YEAR);
    isHijri = getArguments().getBoolean(IS_HIJRI);
    listView.setAdapter(new Adapter(getActivity(), year, isHijri));

    listView.setOnItemClickListener((OnItemClickListener) getParentFragment());

    return view;

}
 
Example 19
Source File: HomeFragment.java    From QuickNews with MIT License 4 votes vote down vote up
public JsonObjectRequest getJokeData(String baseUrl, String parameter, final ListView listView
        , final SwipeRefreshLayout refreshLayout) {
    System.out.println("访问的Url为" + (baseUrl + parameter));
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest((baseUrl + parameter).trim(), null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        System.out.println("Volley得到的response是+" + response.toString());
                        Gson gson = new Gson();
                        JokeData jokeData = gson.fromJson(response.toString(), new TypeToken<JokeData>() {
                        }.getType());
                        List<Joke> jokeList = jokeData.getData();
                        refreshLayout.setRefreshing(false);
                        JokeAdapter adapter = new JokeAdapter(getActivity(), jokeList);
                        listView.setAdapter(adapter);
                        adapter.notifyDataSetChanged();
                        final List<Joke> finalJokeList = jokeList;
                        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                            @Override
                            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                                Intent intent = new Intent(getActivity(), NewsActivity.class);
                                System.out.println("i的位置" + position);
                                System.out.println("newsList的size" + finalJokeList.size());
                                System.out.println("newsList.get(i).getDisplay_url()" + finalJokeList.get(position).getGroup().getShare_url());
                                intent.putExtra("news_url", finalJokeList.get(position).getGroup().getShare_url());
                                startActivity(intent);
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                    }

                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            System.out.println("获取信息失败……");
            System.out.println("error是" + error.toString());

        }
    });

    System.out.println("jsonObjectRequest" + jsonObjectRequest.toString());
    return jsonObjectRequest;
}
 
Example 20
Source File: FMActivity.java    From Kernel-Tuner with GNU General Public License v3.0 4 votes vote down vote up
@Override
   public void onCreate(Bundle savedInstanceState)
{
	//supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
       super.onCreate(savedInstanceState);

	setContentView(R.layout.fm);
	fListView = (ListView) findViewById(R.id.list);

	path = savedInstanceState != null ? savedInstanceState.getString(CURR_DIR) : FILE_SEPARATOR;//Environment.getExternalStorageDirectory().toString();

       fListView.setDrawingCacheEnabled(true);
	fAdapter = new FMAdapter(this, R.layout.fm_row);

	fListView.setAdapter(fAdapter);

	ls(path, false);

	getSupportActionBar().setSubtitle(path);
	fListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
	{
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
									long arg3)
			{
                   FMEntry entry = fAdapter.getItem(pos);
                   if(entry.getType() == TYPE_DIRECTORY || entry.getType() == TYPE_DIRECTORY_LINK)
                   {
                       Parcelable state = fListView.onSaveInstanceState();
                       listScrollStates.put(path, state);
                       backstack.add(path);
                       path = entry.getType() == TYPE_DIRECTORY_LINK ? entry.getLink() : entry.getPath();
                       validatePath();
                       ls(path, false);
                   }
                   else if(entry.getType() == TYPE_FILE || entry.getType() == TYPE_LINK)
                   {
                       //TODO
                   }
			}
		});
	if(savedInstanceState != null)
	{
           backstack = (LinkedList<String>) savedInstanceState.getSerializable(BACKSTACK);
		Parcelable listState = savedInstanceState.getParcelable("list_position");
		if(listState != null)fListView.post(new RestoreListStateRunnable(listState));
	}
   }