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

The following examples show how to use android.widget.ListView#setOnItemClickListener() . These examples are extracted from open source projects. 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 Project: Folding-Android   File: MainActivity.java    License: 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 2
@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 3
@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 4
@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
/**
 * 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 6
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 7
Source Project: DropDownMenu   File: DoubleListView.java    License: 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 8
@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 9
@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 10
@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 11
Source Project: YiBo   File: StatusSubscribeActivity.java    License: 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 12
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 13
Source Project: EBookDownloader   File: History.java    License: 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 Project: listmyaps   File: MainActivity.java    License: 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
@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 16
@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));
	}
   }
 
Example 17
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
@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 19
Source Project: AssistantBySDK   File: ItemEditActivity.java    License: 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 20
Source Project: QuickNews   File: HomeFragment.java    License: 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;
}