List of usage examples for android.widget AdapterView.OnItemClickListener AdapterView.OnItemClickListener
AdapterView.OnItemClickListener
From source file:org.ale.openwatch.FeedFragmentActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(TAG, "onCreate"); mPullToRefreshAttacher = PullToRefreshAttacher.get(this); //mTabHost.setOn setContentView(R.layout.fragment_tabs_pager); this.getSupportActionBar().setDisplayShowTitleEnabled(false); BugSenseHandler.initAndStartSession(getApplicationContext(), SECRETS.BUGSENSE_API_KEY); checkUserStatus(this); GCMUtils.setUpGCM(this); getDisplayWidth();// ww w .jav a 2 s . com mDrawerList = (ListView) findViewById(R.id.left_drawer); mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { selectItem(view, position); } }); mTabHost = (TabHost) findViewById(android.R.id.tabhost); mTabHost.setup(); mViewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabsAdapter(this, mTabHost, mViewPager); mTitleIndicator = (TitlePageIndicator) findViewById(R.id.titles); mTitleIndicator.setViewPager(mViewPager); inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); SharedPreferences profile = getSharedPreferences(Constants.PROFILE_PREFS, 0); internal_user_id = profile.getInt(Constants.INTERNAL_USER_ID, 0); String userThumbnailUrl = null; if (internal_user_id > 0) userThumbnailUrl = OWUser.objects(getApplicationContext(), OWUser.class) .get(internal_user_id).thumbnail_url.get(); setupFeedAndTagMaps(); populateTabsFromMaps(); // See if initiating intent specified a tab via url, feed type if (checkIntentForUri(getIntent())) { } else if (savedInstanceState != null) { mTabHost.setCurrentTabByTag(savedInstanceState.getString("tab")); } else { // set default tab to Top Stories mTitleIndicator.setCurrentItem(2); } onCreateWon = true; ListView mDrawerList = (ListView) findViewById(R.id.left_drawer); // Set the adapter for the list view mDrawerItems.add("divider"); mDrawerItems.addAll(feeds); mDrawerItems.add("divider"); mDrawerItems.addAll(tags); mDrawerList .setAdapter(new DrawerItemAdapter(this, mDrawerItems, drawerTitleToIcon, feeds, userThumbnailUrl)); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.ic_drawer, R.string.drawer_open, R.string.drawer_close) { /** Called when a drawer has settled in a completely closed state. */ public void onDrawerClosed(View view) { getSupportActionBar().setTitle(""); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } /** Called when a drawer has settled in a completely open state. */ public void onDrawerOpened(View drawerView) { getSupportActionBar().setTitle(""); invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() } }; // Set the drawer toggle as the DrawerListener mDrawerLayout.setDrawerListener(mDrawerToggle); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setHomeButtonEnabled(true); mTitleIndicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i2) { } @Override public void onPageSelected(int i) { try { JSONObject analyticsPayload = new JSONObject().put(Analytics.feed, FeedFragmentActivity.this.mTabsAdapter.getPageTitle(i)); Analytics.trackEvent(getApplicationContext(), Analytics.SELECTED_FEED, analyticsPayload); } catch (JSONException e) { e.printStackTrace(); } if (mPullToRefreshAttacher != null) mPullToRefreshAttacher.setRefreshComplete(); Log.i(TAG, String.format("page %d selected", i)); removeVideoView(); if (lastPagePosition != -1) { RemoteRecordingsListFragment frag = ((RemoteRecordingsListFragment) FeedFragmentActivity.this.mTabsAdapter .getItem(lastPagePosition)); if (frag != null) { frag.detachPullToRefresh(); } else Log.i("PTR", String.format("fragment at page %d is null", i)); } lastPagePosition = i; } @Override public void onPageScrollStateChanged(int i) { } }); }
From source file:com.downrighttech.dmxdip.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mThemeManager = new ThemeManager(VERSION.SDK_INT); super.onCreate(savedInstanceState); // load preferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); // Load Theme from preferences mThemeManager.setTheme(Integer.parseInt(mSharedPreferences.getString("pref_theme", "0"))); setTheme(mThemeManager.getTheme());//from w w w . j a v a 2 s . co m setContentView(R.layout.activity_main); //Load Resources button_on = getResources().getDrawable(R.drawable.button_on); button_off = getResources().getDrawable(R.drawable.button_off); // Load Interface Items editText_Start = (EditText) findViewById(R.id.editText_Start); editText_Span = (EditText) findViewById(R.id.EditText_Span); clearButton = (ImageButton) findViewById(R.id.imageButton); toggleButton = new ToggleButton[9]; toggleButton[0] = (ToggleButton) findViewById(R.id.ToggleButton01); toggleButton[1] = (ToggleButton) findViewById(R.id.ToggleButton02); toggleButton[2] = (ToggleButton) findViewById(R.id.ToggleButton03); toggleButton[3] = (ToggleButton) findViewById(R.id.ToggleButton04); toggleButton[4] = (ToggleButton) findViewById(R.id.ToggleButton05); toggleButton[5] = (ToggleButton) findViewById(R.id.ToggleButton06); toggleButton[6] = (ToggleButton) findViewById(R.id.ToggleButton07); toggleButton[7] = (ToggleButton) findViewById(R.id.ToggleButton08); toggleButton[8] = (ToggleButton) findViewById(R.id.ToggleButton09); listView = (ListView) findViewById(R.id.listView1); // Load ArrayList mAddressArray = new ArrayList<Integer>(); mBitArray = new ArrayList<String>(); mAddressArray.ensureCapacity(512); mBitArray.ensureCapacity(512); // Load Fonts Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/RobotoSlab-Regular.ttf"); // Setup Fonts editText_Start.setTypeface(tf); editText_Span.setTypeface(tf); for (int i = 0; i < ADDRESS_BUTTONS; i++) toggleButton[i].setTypeface(tf); //Setup setHapticFeedbackEnabled vib = (Vibrator) this.getSystemService(Service.VIBRATOR_SERVICE); // Events editText_Start.addTextChangedListener(this); editText_Span.addTextChangedListener(this); clearButton.setOnClickListener(this); // What's New Count int dialogCount = mSharedPreferences.getInt("pref_startup_dialog", 0); // If this is a new version, show the Dialog again String lastRunVersion = mSharedPreferences.getString("pref_version", ""); String savedString = getString(R.string.version); if (!lastRunVersion.equals(savedString)) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putString("pref_version", getString(R.string.version)); editor.commit(); dialogCount = 0; } // If the dialog is due to be shown Log.v(TAG, "onCreate dialogCount:" + dialogCount); if (dialogCount == 0) { mDialogManager = new DialogManager(this); mDialogManager.setmIcon(R.drawable.ic_launcher); mDialogManager.setTitle(getText(R.string.app_name) + " - " + getText(R.string.version)); mDialogManager.setMessage(R.string.dialog_about_message); mDialogManager.setPositiveButton(R.string.dialog_yes); mDialogManager.setNeutralButton(R.string.dialog_maybe); mDialogManager.show(getSupportFragmentManager(), "What's New"); } else if (dialogCount > 0) { SharedPreferences.Editor editor = mSharedPreferences.edit(); editor.putInt("pref_startup_dialog", --dialogCount); editor.commit(); } listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(listView.getWindowToken(), 0); } }); listView.setOnScrollListener(new AbsListView.OnScrollListener() { @Override public void onScroll(AbsListView absListView, int i, int i2, int i3) { } @Override public void onScrollStateChanged(AbsListView absListView, int i) { if (i != SCROLL_STATE_IDLE) { InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(listView.getWindowToken(), 0); } } }); }
From source file:com.sakisds.icymonitor.fragments.graph.GraphFragment.java
public void init(String[] names, String dataType, int maxY) { int size = names.length; if (size != 0) { mNames = names;/* ww w . j av a2s . c om*/ mDataType = dataType; mViewValues = new TextView[names.length]; // Setup lines mSeries = new XYSeries[size]; mSeriesRenderer = new XYSeriesRenderer[size]; for (int i = 0; i < size; i++) { mSeries[i] = new XYSeries(""); mSeriesRenderer[i] = new XYSeriesRenderer(); mSeriesRenderer[i].setLineWidth(mLineWidth); mDataset.addSeries(mSeries[i]); mRenderer.addSeriesRenderer(mSeriesRenderer[i]); } // Load colors refreshColors(names, true); // Setup list setListAdapter(new GraphListArrayAdapter(getActivity(), names)); // Setup onclick listener getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView parent, View v, int position, long id) { String name = (String) v.findViewById(R.id.text_name).getTag(R.string.key_name); Intent intent = new Intent(getActivity(), EditActivity.class); intent.putExtra(EXTRAS_COLOR, name + "_" + mDataType); startActivity(intent); } }); // Setup Y axis mRenderer.setYAxisMin(0); mRenderer.setYAxisMax(maxY); // Create graphs mChart = ChartFactory.getLineChartView(getActivity().getBaseContext(), mDataset, mRenderer); mChart.setBackgroundColor(Color.TRANSPARENT); // Add graphs to view ((FrameLayout) mRootView.findViewById(R.id.graph_container)).addView(mChart); } else { names = new String[1]; mViewValues = new TextView[1]; names[0] = "Unsupported"; mDataType = "null"; mSeriesRenderer = new XYSeriesRenderer[1]; mSeriesRenderer[0] = new XYSeriesRenderer(); refreshColors(names, true); setListAdapter(new GraphListArrayAdapter(getActivity(), names)); } }
From source file:cm.aptoide.ptdev.ScheduledDownloadsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Aptoide.getThemePicker().setAptoideTheme(this); super.onCreate(savedInstanceState); setContentView(R.layout.page_sch_downloads); getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowTitleEnabled(true); getSupportActionBar().setTitle(getString(R.string.setting_schdwntitle)); lv = (ListView) findViewById(android.R.id.list); lv.setDivider(null);/*from w ww . j a v a2 s . c om*/ db = new Database(Aptoide.getDb()); bindService(new Intent(this, DownloadService.class), conn, Context.BIND_AUTO_CREATE); adapter = new CursorAdapter(this, null, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER) { @Override public View newView(Context context, Cursor arg1, ViewGroup arg2) { return LayoutInflater.from(context).inflate(R.layout.row_sch_download, null); } @Override public void bindView(View convertView, Context arg1, Cursor c) { // Planet to display ScheduledDownload scheduledDownload = scheduledDownloadsHashMap .get(c.getLong(c.getColumnIndex("_id"))); // The child views in each row. CheckBox checkBoxScheduled; TextView textViewName; TextView textViewVersion; ImageView imageViewIcon; // Create a new row view if (convertView.getTag() == null) { // Find the child views. textViewName = (TextView) convertView.findViewById(R.id.name); textViewVersion = (TextView) convertView.findViewById(R.id.appversion); checkBoxScheduled = (CheckBox) convertView.findViewById(R.id.schDwnChkBox); imageViewIcon = (ImageView) convertView.findViewById(R.id.appicon); // Optimization: Tag the row with it's child views, so we don't have to // call findViewById() later when we reuse the row. convertView.setTag(new Holder(textViewName, textViewVersion, checkBoxScheduled, imageViewIcon)); // If CheckBox is toggled, update the planet it is tagged with. checkBoxScheduled.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { CheckBox cb = (CheckBox) v; ScheduledDownload schDownload = (ScheduledDownload) cb.getTag(); schDownload.setChecked(cb.isChecked()); } }); } // Reuse existing row view else { // Because we use a ViewHolder, we avoid having to call findViewById(). Holder viewHolder = (Holder) convertView.getTag(); checkBoxScheduled = viewHolder.checkBoxScheduled; textViewVersion = viewHolder.textViewVersion; textViewName = viewHolder.textViewName; imageViewIcon = viewHolder.imageViewIcon; } // Tag the CheckBox with the Planet it is displaying, so that we can // access the planet in onClick() when the CheckBox is toggled. checkBoxScheduled.setTag(scheduledDownload); // Display planet data checkBoxScheduled.setChecked(scheduledDownload.isChecked()); textViewName.setText(scheduledDownload.getName()); textViewVersion.setText(scheduledDownload.getVername()); ImageLoader.getInstance().displayImage(scheduledDownload.getIconPath(), imageViewIcon); } }; getSupportLoaderManager().initLoader(0, null, this); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View item, int arg2, long arg3) { ScheduledDownload scheduledDownload = (ScheduledDownload) ((Holder) item.getTag()).checkBoxScheduled .getTag(); scheduledDownload.toggleChecked(); Holder viewHolder = (Holder) item.getTag(); viewHolder.checkBoxScheduled.setChecked(scheduledDownload.isChecked()); } }); if (getIntent().hasExtra("downloadAll")) { ScheduledDownloadsDialog pd = new ScheduledDownloadsDialog(); pd.show(getSupportFragmentManager(), "installAllScheduled"); } lv.setAdapter(adapter); }
From source file:com.eutectoid.dosomething.picker.PickerFragment.java
@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//from w w w . j a va 2s . c om 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; }
From source file:org.occupycincy.android.OccupyCincyActivity.java
private void populateBlogView() { ListView lv = (ListView) findViewById(R.id.lvBlog); ListAdapter la = null;/*from w w w . j av a 2 s. c o m*/ if (feedItems.isEmpty()) { la = new ArrayAdapter<Object>(getApplicationContext(), android.R.layout.simple_list_item_1, new String[] { "No data. Try again later." }); lv.setOnItemClickListener(null); } else { la = new SimpleAdapter(getApplicationContext(), feedItems, R.layout.blog_row, new String[] { "title", "description" }, new int[] { R.id.txtTitle, R.id.txtDescription }); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { //setToast(feedItems.get(position).get("title")); startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(feedItems.get(position).get("link")))); } }); } lv.setAdapter(la); }
From source file:heartware.com.FB_picker.PickerFragment.java
@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/*from ww w . j a v a2s. c o m*/ 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 fb_pickers. return false; } }); listView.setOnScrollListener(onScrollListener); activityCircle = (ProgressBar) view.findViewById(R.id.com_facebook_picker_activity_circle); setupViews(view); listView.setAdapter(adapter); return view; }
From source file:org.sensapp.android.sensappdroid.activities.GraphDisplayerActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.graph_displayer); List<String> data = getIntent().getData().getPathSegments(); graphName = data.get(data.size() - 1); graphID = Long.parseLong(data.get(data.size() - 2)); setTitle(graphName);/*from w w w. j a v a2 s . c o m*/ ListView list = (ListView) findViewById(R.id.list_graph_displayer); list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { GraphWrapper gw = (GraphWrapper) adapterView.getItemAtPosition(i); Callable<Integer> refreshGraphs = new Callable<Integer>() { public Integer call() { return displayGraphs(); } }; GraphSensorOptionsDialogFragment.newInstance(gw.getID(), gw.getName(), refreshGraphs) .show(getSupportFragmentManager(), "newOptionEditor"); } }); list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { GraphWrapper gw = (GraphWrapper) adapterView.getItemAtPosition(i); String where = SensAppContract.GraphSensor.ID + " = \"" + gw.getID() + "\" AND " + SensAppContract.GraphSensor.GRAPH + " = " + graphID; getApplication().getContentResolver().delete(SensAppContract.GraphSensor.CONTENT_URI, where, null); displayGraphs(); return true; } }); getSupportLoaderManager().initLoader(0, null, this); displayGraphs(); }
From source file:io.jari.geenstijl.Blog.java
public void reloadDrawer() { ListView accountList = (ListView) findViewById(R.id.login); TextView sectionheader = (TextView) findViewById(R.id.sectionheader_account); if (API.loggedIn(this)) { sectionheader.setText(API.getUsername(this).toUpperCase()); ArrayAdapter<String> accountAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, R.id.wrap_text, new String[] { getResources().getString(R.string.logout) }); accountList.setAdapter(accountAdapter); accountList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawerLayout.closeDrawers(); new ConfirmLogoutDialog(Blog.this).show(getSupportFragmentManager(), "LgtCnfrmDg"); }/*from www . j a v a 2 s . com*/ }); } else { ArrayAdapter<String> accountAdapter = new ArrayAdapter<String>(this, R.layout.drawer_list_item, R.id.wrap_text, new String[] { getResources().getString(R.string.login) }); accountList.setAdapter(accountAdapter); sectionheader.setText(R.string.sectionheader_account); accountList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { drawerLayout.closeDrawers(); new LoginDialog(Blog.this).show(getSupportFragmentManager(), "LgnDg"); } }); } }
From source file:com.dattasmoon.pebble.plugin.IgnorePreference.java
@Override protected void onBindDialogView(View view) { btnAdd = (Button) view.findViewById(R.id.btnAdd); etMatch = (EditText) view.findViewById(R.id.etMatch); chkRawRegex = (CheckBox) view.findViewById(R.id.chkRawRegex); chkCaseInsensitive = (CheckBox) view.findViewById(R.id.chkCaseInsensitive); actvApplications = (AutoCompleteTextView) view.findViewById(R.id.actvApplications); spnApplications = (Spinner) view.findViewById(R.id.spnApplications); spnMode = (Spinner) view.findViewById(R.id.spnMode); lvIgnore = (ListView) view.findViewById(R.id.lvIgnore); lvIgnore.setAdapter(arrayAdapter);/*w ww. j av a2 s . c o m*/ lvIgnore.setEmptyView(view.findViewById(android.R.id.empty)); new LoadAppsTask().execute(); lvIgnore.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) { AdapterView.AdapterContextMenuInfo contextInfo = (AdapterView.AdapterContextMenuInfo) menuInfo; int position = contextInfo.position; long id = contextInfo.id; // the child view who's info we're viewing (should be equal to v) final View v = contextInfo.targetView; MenuInflater inflater = new MenuInflater(getContext()); inflater.inflate(R.menu.preference_ignore_context, menu); //we have to do this mess because DialogPreference doesn't allow for onMenuItemSelected or onOptionsItemSelected. Bleh menu.findItem(R.id.btnEdit).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { final int arrayPosition = (Integer) v.getTag(); final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString(); JSONArray temp = new JSONArray(); for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) { try { JSONObject ignore = arrayAdapter.getJSONArray().getJSONObject(i); if (i == arrayPosition) { etMatch.setText(ignore.getString("match")); chkRawRegex.setChecked(ignore.getBoolean("raw")); chkCaseInsensitive.setChecked(ignore.optBoolean("insensitive", true)); String app = ignore.getString("app"); if (app == "-1") { actvApplications.setText(getContext().getString(R.string.ignore_any)); } else { actvApplications.setText(app); } boolean exclude = ignore.optBoolean("exclude", true); if (exclude) { spnMode.setSelection(Constants.IgnoreMode.EXCLUDE.ordinal()); } else { spnMode.setSelection(Constants.IgnoreMode.INCLUDE.ordinal()); } continue; } temp.put(ignore); } catch (JSONException e) { e.printStackTrace(); } } arrayAdapter.setJSONArray(temp); arrayAdapter.notifyDataSetChanged(); return true; } }); menu.findItem(R.id.btnDelete).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext()); final int arrayPosition = (Integer) v.getTag(); final String text = ((TextView) v.findViewById(R.id.tvItem)).getText().toString(); builder.setMessage(getContext().getResources().getString(R.string.confirm_delete) + " '" + text + "' ?") .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { JSONArray temp = new JSONArray(); for (int i = 0; i < arrayAdapter.getJSONArray().length(); i++) { if (i == arrayPosition) { continue; } try { temp.put(arrayAdapter.getJSONArray().getJSONObject(i)); } catch (JSONException e) { e.printStackTrace(); } } arrayAdapter.setJSONArray(temp); arrayAdapter.notifyDataSetChanged(); } }).setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // User cancelled the dialog } }); builder.create().show(); return true; } }); } }); btnAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { JSONObject item = new JSONObject(); try { item.put("match", etMatch.getText().toString()); item.put("raw", chkRawRegex.isChecked()); item.put("insensitive", chkCaseInsensitive.isChecked()); if (actvApplications.getText().toString() .equalsIgnoreCase(getContext().getString(R.string.ignore_any))) { item.put("app", "-1"); } else { item.put("app", actvApplications.getText().toString()); } if (spnMode.getSelectedItemPosition() == Constants.IgnoreMode.INCLUDE.ordinal()) { item.put("exclude", false); } else { item.put("exclude", true); } if (Constants.IS_LOGGABLE) { Log.i(Constants.LOG_TAG, "Item is: " + item.toString()); } arrayAdapter.getJSONArray().put(item); etMatch.setText(""); arrayAdapter.notifyDataSetChanged(); } catch (JSONException e) { e.printStackTrace(); } } }); actvApplications.setText(getContext().getString(R.string.ignore_any)); actvApplications.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { actvApplications.showDropDown(); } }); actvApplications.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ApplicationInfo pkg = (ApplicationInfo) parent.getItemAtPosition(position); if (pkg == null) { actvApplications.setText(getContext().getString(R.string.ignore_any)); } else { actvApplications.setText(pkg.packageName); } } }); actvApplications.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { actvApplications.showDropDown(); } else { if (actvApplications.getText().length() == 0) { actvApplications.setText(getContext().getString(R.string.ignore_any)); } } } }); super.onBindDialogView(view); }