How to Add Section Indexers in a Android List View Crete the Adapter for list view . public class ContactsAdapter extends BaseAdapter implements SectionIndexer { Context context; String[] strings; String[] sections ; HashMap alphaIndexer; public ContactsAdapter(Context context, String[] strings) { this.context = context; this.strings = strings; alphaIndexer = new HashMap (); int size = strings.length; for (int x = 0; x < size; x++) { String s = strings[x]; String ch = s.substring(0, 1); ch = ch.toUpperCase(); if (!alphaIndexer.containsKey(ch)) alphaIndexer.put(ch, x); } Set sectionLetters = alphaIndexer.keySet(); ArrayList sectionList = new ArrayList<>(sectionLetters); Collections.sort(sectionList); sections = new String[sectionList.size()]; sectionList.toArray(sections); } @Overr
Posts
Getting The Current Location from the Android device Also getting the address from that location
- Get link
- Other Apps
hey guys in this tutorial i will show u guys how to get the location from your android device and find the address of the location from that device. please add these permissions public class LocationFinder implements LocationListener { Context context; Double lat, lon; Location location; public LocationFinder(Context c) { this.context = c; LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10, 1000 * 60 * 1, this); try { location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); setLat(location.getLatitude()); setLon(location.getLongitude()); }catch (Exception e){ Toast.makeText(c,"couldn't locate your location",Toast.LENGTH_LONG).show(); setLat(21.0000);
Adding Markers in Google Map and Focusing Camera when map loaded
- Get link
- Other Apps
Map fragment :xml design Map fragment class public class MapView extends Fragment { View view; Bundle bundle; GoogleMap map; Marker marker; String name, vicinity, lat, lng, distance; public SupportMapFragment mapFragment; ImageView home_button, map_button, review_button; public MapView() { // Required empty public constructor } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (view == null) { view = inflater.inflate(R.layout.map_view, container, false); } else { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) { parent.removeView(view); } } return view; } @Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState);
Creating a Broadcast Receiver in android
- Get link
- Other Apps
hey guys , In this tutorial i am going to show how to create a simple broadcast receiver ,which makes your phone vibrate when the charger is connected 1 step: create an android project as you do always then create a class wich extends broadcast receiver class import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Vibrator; import android.widget.Toast; public class Vibrated extends BroadcastReceiver{ @Override public void onReceive(Context context, Intent arg1) { Toast.makeText(context, "Don't panik but your time is up!!!!.", Toast.LENGTH_LONG).show(); // Vibrate the mobile phone Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(4000); Toast.makeText(context, "vibrated!!!!.", Toast.LENGTH_LONG).show(); } } 2 step: in your androidmanifest.xml file add the vibrator pe
Handling multiple view Clicks
- Get link
- Other Apps
hey guys in this tutorial i will show you guys multiple ways to handle the clicks in the view of an android... 1 method: ImageButton btplus = (ImageButton)findViewById(R.id.btplus); btplus.setOnClickListener( new ImageButton.OnClickListener(){ @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "+", Toast.LENGTH_SHORT).show(); } }); ImageButton btminus = (ImageButton)findViewById(R.id.btminus); btminus.setOnClickListener( new ImageButton.OnClickListener(){ @Override public void onClick(View v) { Toast.makeText(getApplicationContext(), "-", Toast.LENGTH_SHORT).show(); } }); 2 method: for implemnting this method your activity class must implement OnClickListener interface then override the onClick class ImageButton btminus = (ImageButton)findViewById(R.id.btminus); btminus.setOnClickListener(this); ImageButton
Simple file uploading in android
- Get link
- Other Apps
Hey guys, In this blog i will give you a code snippet which might come handi in file uploading import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.net.HttpURLConnection; import java.net.URL; public class DoFileUplaod { public DoFileUplaod(String FtoSave, String urlServer,String tag) { System.out.println("doupload" + FtoSave); HttpURLConnection connection = null; DataOutputStream outputStream = null; String pathToOurFile = FtoSave; System.out.println("url-----" + urlServer); String lineEnd = "\r\n"; String twoHyphens = "--"; String boundary = "*****"; int bytesRead, bytesAvailable, bufferSize; byte[] buffer; int maxBufferSize = 1 * 1024 * 1024; try { System.out.println("onee"); FileInputStream fileInputStream = new FileInp
Creating Simple Horizontal graph in android using android Weight property without any External Libraries
- Get link
- Other Apps
Hi Coders , This a simple example for how to make simple graph in android without using any external library this a small part of the my xml file wich is used make the graph part,Hope you guys can do the rest.. the out put of the graph is given at the bottom.. Initially i set the weight of each text view to 50 dp this my java code friend there might me some extra codes because its part of my project, so i cant show the entire project ... The libary name Ion is used for getting the json data from the web,and according to that value graph is set TextView c1gtexy=(TextView )FindViewById(R.id.country1_bar); TextView c2gtexy=(TextView )FindViewById(R.id.country2_bar); TextView c1gtexy=(TextView )FindViewById(R.id.country1_bar); TextView c2gtexy=(TextView )FindViewById(R.id.country2_bar); public void getPredictions() { if (new NetworkData().isNetworkAvailable(this)) { Ion.with(getApplicationContext())