List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:com.metaphyze.hackernewsfrontpage.HackerNewsFrontPageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hacker_news_front_page); bookFileName = getFilesDir() + File.separator + "bookmarked_posts.js"; drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerList = (ListView) findViewById(R.id.drawer); location = (TextView) findViewById(R.id.location); webView = (WebView) findViewById(R.id.content_frame); webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setDomStorageEnabled(true); webView.getSettings().setAppCacheEnabled(true); loadingView = findViewById(R.id.loading); ProgressBar progressBar = ((ProgressBar) findViewById(R.id.progress_bar)); progressBar.setIndeterminate(true);/*from ww w . ja v a 2s . c om*/ drawerList.setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item, new ArrayList<HackerNewsPost>(), true)); getActionBar().setTitle("Hacker News Front Page (Loading Live Stream...)"); drawerList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { HackerNewsPost post = (HackerNewsPost) parent.getItemAtPosition(position); webView.loadUrl(post.getUrl()); webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { super.onPageStarted(view, url, favicon); loadingView.setVisibility(View.VISIBLE); location.setText("LOADING......" + url); } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); loadingView.setVisibility(View.INVISIBLE); location.setText(url); } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { view.loadUrl(url); return true; } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { loadingView.setVisibility(View.INVISIBLE); location.setText("ERROR LOADING PAGE"); view.loadUrl("file:///android_asset/failed_to_load_page.html"); } }); drawerLayout.closeDrawer(drawerList); } }); drawerList.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { final HackerNewsPost clonedPost = ((HackerNewsPost) parent.getItemAtPosition(position)).clone(); clonedPost.setPostedAgo(new Date().toString()); AlertDialog.Builder builder = new AlertDialog.Builder(HackerNewsFrontPageActivity.this); if (((HackerNewsAdapter) parent.getAdapter()).isLive()) { builder.setTitle("Bookmark?"); builder.setMessage("Do you want to bookmark the post\n" + clonedPost.getTitle()); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { HackerNewsFrontPageContents contents = readContentsFromBookmarksFile(); if (contents == null) { showError("ERROR", "Failed to read bookmark file"); dialog.dismiss(); return; } if (!contents.addPost(clonedPost)) { showError("Already Exists", "Not added becasue bookmark already exists"); dialog.dismiss(); return; } if (!saveContentsToBookmarksFile(contents)) { showError("ERROR", "Failed to save bookmark"); dialog.dismiss(); } } catch (Exception ex) { ex.printStackTrace(); showError("ERROR", "Internal error: " + ex); } } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } else { builder.setTitle("Delete?"); builder.setMessage("Do you want to delete the bookmarked post:\n" + clonedPost.getTitle()); builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { try { HackerNewsFrontPageContents contents = readContentsFromBookmarksFile(); if (contents == null) { showError("ERROR", "Unable to find or generate bookmarks file"); dialog.dismiss(); return; } if (!contents.removePost(clonedPost)) { showError("Not Removed", "Does not exist? How's that possible?"); dialog.dismiss(); return; } if (saveContentsToBookmarksFile(contents)) { if (contents.getItems().size() > 0) { drawerList .setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item, contents.getItems(), false)); } else { showError("No more bookmarks", "Reverting to live stream"); loadLiveStream(); } } else { showError("ERROR", "Failed to save bookmark deletion"); } dialog.dismiss(); } catch (Exception ex) { ex.printStackTrace(); showError("ERROR", "Internal Error: " + ex); } } }).setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } builder.setCancelable(true); builder.create().show(); return false; } }); drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.drawer_icon, 0, 0); drawerLayout.setDrawerListener(drawerToggle); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // actionBar.setHomeButtonEnabled(true); requestQueue = Volley.newRequestQueue(this); loadLiveStream(); }
From source file:com.cypress.cysmart.BLEServiceFragments.FindMeService.java
/** * Method to get required characteristics from service *//*from w w w . j a va 2 s . c o m*/ private void getGattData() { LinearLayout ll_layout = (LinearLayout) rootView.findViewById(R.id.linkloss_layout); LinearLayout im_layout = (LinearLayout) rootView.findViewById(R.id.immalert_layout); LinearLayout tp_layout = (LinearLayout) rootView.findViewById(R.id.transmission_layout); RelativeLayout tpr_layout = (RelativeLayout) rootView.findViewById(R.id.transmission_rel_layout); for (int position = 0; position < mExtraservice.size(); position++) { HashMap<String, BluetoothGattService> item = mExtraservice.get(position); BluetoothGattService bgs = item.get("UUID"); List<BluetoothGattCharacteristic> gattCharacteristicsCurrent = bgs.getCharacteristics(); for (final BluetoothGattCharacteristic gattCharacteristic : gattCharacteristicsCurrent) { String uuidchara = gattCharacteristic.getUuid().toString(); if (uuidchara.equalsIgnoreCase(GattAttributes.ALERT_LEVEL)) { if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.LINK_LOSS_SERVICE)) { ll_layout.setVisibility(View.VISIBLE); mSpinnerLinkLoss = (CustomSpinner) rootView.findViewById(R.id.linkloss_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_linkloss = ArrayAdapter.createFromResource(getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_linkloss.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerLinkLoss.setAdapter(adapter_linkloss); mSpinnerLinkLoss.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } if (bgs.getUuid().toString().equalsIgnoreCase(GattAttributes.IMMEDIATE_ALERT_SERVICE)) { im_layout.setVisibility(View.VISIBLE); mSpinnerImmediateAlert = (CustomSpinner) rootView.findViewById(R.id.immediate_spinner); // Create an ArrayAdapter using the string array and a // default // spinner layout ArrayAdapter<CharSequence> adapter_immediate_alert = ArrayAdapter.createFromResource( getActivity(), R.array.findme_immediate_alert_array, android.R.layout.simple_spinner_item); // Specify the layout to use when the list of choices // appears adapter_immediate_alert .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // Apply the adapter to the spinner mSpinnerImmediateAlert.setAdapter(adapter_immediate_alert); mSpinnerImmediateAlert.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("No Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_NO_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("Mid Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_MID_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_MID_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } if (parent.getItemAtPosition(position).toString().equalsIgnoreCase("High Alert")) { byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT); BluetoothLeService.writeCharacteristicNoresponse(gattCharacteristic, convertedBytes); Toast.makeText(getActivity(), getResources().getString(R.string.find_value_written_toast) + IMM_HIGH_ALERT_TEXT + getResources().getString(R.string.find_value_success_toast), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } }); } } if (uuidchara.equalsIgnoreCase(GattAttributes.TRANSMISSION_POWER_LEVEL)) { tp_layout.setVisibility(View.VISIBLE); tpr_layout.setVisibility(View.VISIBLE); mReadCharacteristic_tp = gattCharacteristic; mTransmissionPower = (ImageView) rootView.findViewById(R.id.findme_tx_power_img); mTransmissionPowerValue = (TextView) rootView.findViewById(R.id.findme_tx_power_txt); if (mReadCharacteristic_tp != null) { prepareBroadcastDataReadtp(mReadCharacteristic_tp); } } } } }
From source file:androidGLUESigner.ui.Fragments.SignedDocListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.settingsHelper = new SettingsHelper(getActivity()); this.view = inflater.inflate(R.layout.fragment_sdoclist, container, false); final ListView listview = (ListView) view.findViewById(R.id.sdocListView); list = settingsHelper.getSignedDocList(); adapter = new SdocListAdapter(getActivity(), android.R.layout.simple_list_item_1, list); listview.setAdapter(adapter);//ww w . jav a2 s .co m listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { SignedDocActivity activity = (SignedDocActivity) getActivity(); activity.launchReader(list.get(position)); } }); listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) { final String item = (String) parent.getItemAtPosition(position); showDeleteButton(item, list); return true; } }); this.deleteButton = (ImageButton) view.findViewById(R.id.sigListDeleteButton); return view; }
From source file:org.peercast.pecaport.PecaPortFragmentBase.java
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mContentView = (ContainerFrame) view; final Spinner vWanConnectionSelector = (Spinner) mContentView.findViewById(R.id.vWanConnectionSelector); final TableView vMappingEntries = (TableView) mContentView.findViewById(R.id.vMappingEntries); vPeerCast = (PeerCastButton) mContentView.findViewById(R.id.vPeerCast); final ImageButton vAdd = (ImageButton) mContentView.findViewById(R.id.vAdd); if (!mPreferences.isDebug()) vAdd.setVisibility(View.GONE); mWanConnectionAdapter = new WanConnectionsAdapter(); vWanConnectionSelector.setAdapter(mWanConnectionAdapter); final AdapterView.OnItemSelectedListener wanItemListener = new AdapterView.OnItemSelectedListener() { @Override/*from w w w . ja v a 2 s. c om*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { WanConnection conn = (WanConnection) parent.getItemAtPosition(position); String externalIp = conn.getExternalIp(); if (externalIp == null) externalIp = getContext().getString(R.string.t_empty); mViewBinder.updateTextView(R.id.vWanExternalIp, externalIp); onPreparePeerCastButton(vPeerCast, conn); mMappingAdapter.setPortMappings(conn.getMappingEntries()); updateAddButton(vAdd); } @Override public void onNothingSelected(AdapterView<?> parent) { } }; vWanConnectionSelector.setOnItemSelectedListener(wanItemListener); mWanConnectionAdapter.registerDataSetObserver(new DataSetObserver() { @Override public void onChanged() { int enabledPos = mWanConnectionAdapter.getConnectedPosition(); if (enabledPos != -1) { wanItemListener.onItemSelected(vWanConnectionSelector, null, enabledPos, 0); } updateAddButton(vAdd); } }); mMappingAdapter = new MappingEntryAdapter(getContext(), new View.OnClickListener() { @Override public void onClick(View v) { onDeleteMapping((WanConnection) vWanConnectionSelector.getSelectedItem(), (PortMapping) v.getTag()); } }); vMappingEntries.setAdapter(mMappingAdapter); vPeerCast.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //Log.d(TAG, "" + v); WanConnection conn = (WanConnection) vWanConnectionSelector.getSelectedItem(); if (conn != null) onClickPeerCastButton(vPeerCast, conn); else showToast("WanConnection not found."); } }); vAdd.setEnabled(mActiveNicInfo != null); vAdd.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { onRequestAddPort(mWanConnectionAdapter.getConnected()); } }); }
From source file:org.namelessrom.devicecontrol.MainActivity.java
@Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { loadFragmentPrivate((Integer) adapterView.getItemAtPosition(i), false); }
From source file:com.example.lowviscam.GalleryActivity.java
/** * Callback method for a when a coupon is clicked. A new share intent is created with the * coupon title. Then the user can select which app to share the content of the coupon with. * * @param parent The AdapterView where the click happened. * @param view The view within the AdapterView that was clicked (this * will be a view provided by the adapter). * @param position The position of the view in the adapter. * @param id The row id of the item that was clicked. *//* w w w . ja v a 2s .c o m*/ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Find coupon that was clicked based off of position in adapter Coupon coupon = (Coupon) parent.getItemAtPosition(position); Intent intent = new Intent(this, ViewImage.class); /*myIntent.putExtra("key", value);*/ intent.putExtra("mImageUri", coupon.mImageUri.toString()); GalleryActivity.this.startActivity(intent); }
From source file:com.example.amit.tellymoviebuzzz.ImdbUpcomingFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ImdbUpcomingAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.imdbupcoming_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_imdbupcoming_movies); listView.setAdapter(mForecastAdapter); final String[] str1 = { "Action", "Adventure", "Animation", "Comedy", "Crime", "Documentary", "Drama", "Family", "Fantasy", "Foreign", "History", "Horror", "Music", "Mystery", "Romance", "Science Fiction", "TV Movie", "Thriller", "War", "Western", "Others" }; Spinner sp2 = (Spinner) rootView.findViewById(R.id.spinnerupcomingyear); //final Spinner sp2= (Spinner) findViewById(R.id.spinner2); ArrayAdapter<String> adp2 = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, str1);/* w w w.j a va2s .c o m*/ adp2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp2.setAdapter(adp2); sp2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { // TODO Auto-generated method stub // Toast.makeText(getBaseContext(),list.get(position), Toast.LENGTH_SHORT).show(); String val = str1[position]; Bundle bund = new Bundle(); bund.putString("choice", val); // bund. getLoaderManager().restartLoader(FORECAST_LOADER, bund, ImdbUpcomingFragment.this); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); // Spinner spinner = (Spinner) rootView.findViewById(R.id.spinnerthisyear); /// String[] options = {"India","USA","UK"}; // android.R.layout.support_simple_spinner_dropdown_item // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "thisyear"; //Utility.getPreferredMovie(getActivity()); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING))); Intent intent = new Intent(getActivity(), DetailActivity.class); // .setData(cursor.getString(ImdbUpcomingFragment.COL_TMDBID)); intent.putExtra("movieid", cursor.getString(ImdbUpcomingFragment.COL_TMDBID)); startActivity(intent); } } }); return rootView; }
From source file:com.example.amit.tellymoviebuzzz.ImdbFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ImdbAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.imdbthisyear_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView1 = (ListView) rootView.findViewById(R.id.listview_imdbthisyear_movies); listView1.setAdapter(mForecastAdapter); final String[] str = { "Action", "Adventure", "Animation", "Comedy", "Crime", "Documentary", "Drama", "Family", "Fantasy", "Foreign", "History", "Horror", "Music", "Mystery", "Romance", "Science Fiction", "TV Movie", "Thriller", "War", "Western", "Others" }; Spinner sp1 = (Spinner) rootView.findViewById(R.id.spinnerthisyear); //final Spinner sp2= (Spinner) findViewById(R.id.spinner2); ArrayAdapter<String> adp1 = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, str);/*from ww w . j av a2 s .co m*/ adp1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); sp1.setAdapter(adp1); sp1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) { // TODO Auto-generated method stub // Toast.makeText(getBaseContext(),list.get(position), Toast.LENGTH_SHORT).show(); String val = str[position]; Bundle bund = new Bundle(); bund.putString("choice", val); // bund. getLoaderManager().restartLoader(FORECAST_LOADER, bund, ImdbFragment.this); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); // Spinner spinner = (Spinner) rootView.findViewById(R.id.spinnerthisyear); /// String[] options = {"India","USA","UK"}; // android.R.layout.support_simple_spinner_dropdown_item // We'll call our MainActivity listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "thisyear"; //Utility.getPreferredMovie(getActivity()); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, cursor.getString(COL_MOVIE_SETTING))); Intent intent = new Intent(getActivity(), DetailActivity.class); // .setData(cursor.getString(ImdbFragment.COL_TMDBID)); intent.putExtra("movieid", cursor.getString(ImdbFragment.COL_TMDBID)); startActivity(intent); } } }); return rootView; }
From source file:alaindc.memenguage.View.MainActivity.java
private void updateWordsList() { wordsListview = (ListView) findViewById(R.id.wordslistview); adapter = new WordsAdapter(this, crs, 0); adapter.setFilterQueryProvider(new FilterQueryProvider() { public Cursor runQuery(CharSequence constraint) { return dbmanager.getMatchingWords(String.valueOf(constraint)); }//from w w w . j ava 2 s.c o m }); wordsListview.setAdapter(adapter); wordsListview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { Intent createWordIntentActivity = new Intent(MainActivity.this, CreateEditActivity.class); createWordIntentActivity.setAction(Constants.ACTION_EDIT_WORD); Cursor crs = (Cursor) arg0.getItemAtPosition(pos); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ITA, crs.getString(crs.getColumnIndex(Constants.FIELD_ITA))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ENG, crs.getString(crs.getColumnIndex(Constants.FIELD_ENG))); createWordIntentActivity.putExtra(Constants.EXTRA_EDIT_ID, id); MainActivity.this.startActivity(createWordIntentActivity); return true; } }); wordsListview.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long id) { crs = (Cursor) arg0.getItemAtPosition(pos); String text = "Memory level: " + crs.getInt(crs.getColumnIndex(Constants.FIELD_RATING)) + "/5"; text = text + "\nLast edit: " + Utils.getDate(crs.getLong(crs.getColumnIndex(Constants.FIELD_TIMESTAMP))); crs = dbmanager.getContextById(id); if (crs != null && crs.getCount() > 0) { crs.moveToFirst(); String cont = crs.getString(crs.getColumnIndex(Constants.FIELD_CONTEXT)); text = text + "\n\n" + ((cont.equals("")) ? "Add a context sentence" : "Context:\n" + cont); } Toast t = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG); t.setGravity(Gravity.TOP, 0, 250); t.show(); } }); //Toast.makeText(getApplicationContext(), adapter.getCount()+" words in Memenguage", Toast.LENGTH_SHORT).show(); }
From source file:com.sunmeng.educationaladministration.animateview.GoogleCardsActivity.java
/** * Item??/*www .j av a2 s.c o m*/ */ public void getDetails() { listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final Map<String, Object> map; map = (Map<String, Object>) parent.getItemAtPosition(position); LayoutInflater inflater1 = getLayoutInflater(); View view1 = inflater1.inflate(R.layout.activity_extra_detailsinfo, (ViewGroup) findViewById(R.id.toast_layout)); final Spinner spn_extraclassName = (Spinner) view1.findViewById(R.id.spn_uextraclassName); final TextView tv_date = (TextView) view1.findViewById(R.id.ued_date_reply); final EditText et_teacher = (EditText) view1.findViewById(R.id.et_uextrateacher); final EditText et_jointeacher = (EditText) view1.findViewById(R.id.et_uextrajoin); final EditText et_address = (EditText) view1.findViewById(R.id.et_uaddress); final TextView tv_update_reply = (TextView) view1.findViewById(R.id.tvUpdate); final EditText et_uatime = (EditText) view1.findViewById(R.id.et_uatime); img_back = (ImageView) view1.findViewById(R.id.ivBack); img_back.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); /** * ??? */ httpUtils.send(HttpRequest.HttpMethod.GET, HttpClientUtil.HTTP_URL + "ClassAllServlet", new RequestCallBack() { @Override public void onSuccess(final ResponseInfo responseInfo) { //Toast.makeText(mContext, responseInfo.toString(), Toast.LENGTH_LONG).show(); final List<String> list = new ArrayList<String>(); list.add("cnname"); list.add("cnid"); new AsyncTask<String, String, Map<String, String>>() { @Override protected Map<String, String> doInBackground(String... params) { classNameArr = JsonUtil .getJsonToSpinnerListMap(responseInfo.result.toString(), list); return classNameArr; } @Override protected void onPostExecute(Map<String, String> s) { //android.R.layout.simple_spinner_dropdown_item// //R.layout.myspinner spn_extraclassName.setAdapter( new android.widget.ArrayAdapter<String>(GoogleCardsActivity.this, android.R.layout.simple_spinner_dropdown_item, Utils.getMapListToListString(s))); if (map.get("cnname").toString() != "") { spn_extraclassName.setSelection( Utils.getMapListId(s, map.get("cnname").toString())); spn_extraclassName.setEnabled(false); } else { } // et_classname_reply.setSelection(2, true); } }.execute(""); } @Override public void onFailure(HttpException e, String s) { } }); et_teacher.setText(map.get("ateacher").toString()); et_jointeacher.setText(map.get("ajointeacher").toString()); et_address.setText(map.get("aaddress").toString()); tv_date.setText(map.get("adate").toString()); et_uatime.setText(map.get("atime").toString()); tv_update_reply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (tv_update_reply.getText().equals("")) { setClickble(true); tv_update_reply.setText("?"); } else if (tv_update_reply.getText().equals("?")) { setClickble(false); tv_update_reply.setText(""); // TODO ?? updateReply(); } } /** * ?? */ private void setClickble(boolean flag) { et_teacher.setEnabled(flag); et_jointeacher.setEnabled(flag); et_address.setEnabled(flag); spn_extraclassName.setEnabled(flag); et_uatime.setEnabled(flag); } public void updateReply() { String etteacher = et_teacher.getText().toString().trim(); String etjointeacher = et_jointeacher.getText().toString().trim(); String ettime = et_uatime.getText().toString().trim(); String etaddress = et_address.getText().toString().trim(); String tvdate = tv_date.getText().toString().trim(); String classnumid = classNameArr .get(spn_extraclassName.getSelectedItem().toString().trim());//?id String id = map.get("aid").toString(); //Toast.makeText(GoogleCardsActivity.this, "="+etteacher+etjointeacher+ettime+etaddress, Toast.LENGTH_SHORT).show(); if ("".equals(etteacher) && "".equals(etjointeacher) && "".equals(etaddress)) { Toast.makeText(GoogleCardsActivity.this, "???", Toast.LENGTH_SHORT) .show(); return; } else { RequestParams params = new RequestParams(); params.addBodyParameter("activitiesupcdate", tvdate); params.addBodyParameter("activitiesuptime", ettime); params.addBodyParameter("activitiesupclassnumid", classnumid); params.addBodyParameter("activitiesupteacher", etteacher); params.addBodyParameter("activitiesupjointeacher", etjointeacher); params.addBodyParameter("activitiesupaddress", etaddress); params.addBodyParameter("activitiesuprid", id); Toast.makeText(GoogleCardsActivity.this, "id==" + id, Toast.LENGTH_SHORT).show(); httpUtils.send(HttpRequest.HttpMethod.POST, HttpClientUtil.HTTP_URL + "ActivitiesUpdateServlet", params, new RequestCallBack() { @Override public void onSuccess(ResponseInfo responseInfo) { Toast.makeText(GoogleCardsActivity.this, "?", Toast.LENGTH_SHORT).show(); getData(); dialog.cancel(); } @Override public void onFailure(HttpException e, String s) { Toast.makeText(GoogleCardsActivity.this, "", Toast.LENGTH_SHORT).show(); } }); } } }); builder = new AlertDialog.Builder(parent.getContext()); builder.setView(view1); dialog = builder.create(); dialog.show(); } }); }