Thursday, 4 December 2014

How to mount Moto-G/Moto-E on Ubuntu


How to mount Moto-G/Moto-E on Ubuntu and Debug through Eclipse

Moto G is an Android smartphone that does not have a microSD slot. So, the storage of the smartphone cannot be extended. If you want to transfer files between your Ubuntu computer and the Moto G, there are 3 possible ways to do that: FTP over wireless, PTP over USB and MTP over USB.

If your Ubuntu computer has wireless, I highly recommend using FTP over wireless. It is convenient (no wires!), offers good transfer speed and the entire /sdcard contents are available for read and write.

If your Ubuntu computer does not have wireless, then your next option is to use a micro-USB-to-USB cable. The choices here are PTP and MTP. You can enable and switch between the two after you connect Moto G to your computer using a USB cable. If you enable PTP, then Moto G is automatically mounted as a partition in Nautilus. However, you will only be able to see the /sdcard/DCIM and /sdcard/Pictures directories. If you are transferring photos, then this option offers good transfer speed.

If your Ubuntu computer does not have wireless and you still want to read and write to the contents of /sdcard then the option left to you is MTP.

There are many solutions offered online to mount the contents of /sdcard using MTP.
Install the MTP packages:
$ sudo apt-get install mtp-tools mtpfs

Connect Moto G using a USB cable to your computer. Make sure MTP is selected, and not PTP.
Find out the vendor ID and product ID of Moto G using mtp-detect.

$ sudo mtp-detect

You need to press Ctrl+C to stop the command. For the Moto G, you can see that the vendor ID is 22b8 and product ID is 2e82.
Open a new file /etc/udev/rules.d/51-android.rules using sudo and add this line:
SUBSYSTEM=="usb", ATTR{idVendor}=="22b8", ATTR{idProduct}=="2e82", MODE="0666"

Restart the USB service and create a directory to mount the Moto G:
$ sudo service udev restart
$ sudo mkdir /media/motog
$ sudo chmod a+rwx /media/motog
$ sudo adduser your-user-name fuse

Open the /etc/fuse.conf file as sudo and uncomment the line for user_allow_other
Restart your computer. Connect back the Moto G to the computer.
You can now mount the /sdcard of your Moto G using this command:
$ mtpfs -o allow_other /media/motog/

Note that the mounting operation is slow and might take about a minute.

You can find all the directories and files in /sdcard of Moto G in /media/motog. You can read and write to these directories.
To unmount use this command:

$ fusermount -u /media/motog/

Connect Your Device in Debugging Mode!! on UBUNTU(Nook,Moto-E,Moto-G,Samsung)

How to Connect Your Nook,Samsung,Motorola,Micromax Device in Debugging mode through eclipse??


Before Reading this tutorial, You must be sure, you have set-up Environment Variable in Ubuntu(To access android).

When you working on linux, so many person faces the problem: Access your device in debugging mode through eclipse.This is not so difficult after reading this contents:

1. When You trying to access your device as debug mode, first you enable debugging mode inside your phone/tablet.

2. To access debugging mode through eclipse, you must have to create a udev rule for the device.
So How You can find udev:
2a: Open your terminal(ctrl+alt+t).
2b: Then You must logged as root.(sudo -i)
2c: cd /etc -> cd udev
2d: Now list your files(ls)
2e: You can see one directory name as rules.d
2f: Inside this directory, you have to create one file 51-android.rules
    gedit 51-android.rules
   
   

3. In the rules file, each device manufacturer is identified by a unique vendor ID, as specified by the ATTR{idVendor} property.
To see all {idVendor} follow http://developer.android.com/tools/device.html#VendorIds

4. How to establish the permissions for Specific Device?
   Inside your console, type: lsusb

 
   

   You can see Device-id for every device.For example in above picture, motorola id :22b8,which is corrently connected in my computer. Only this id I need to add inside 51-android.rules file.
Add the following line to your file about Android devices(Inside->51-android.rules):
SUBSYSTEM=="usb", SYSFS{idVendor}=="22b8", MODE="0666"
In this example, the vendor ID is for Motorola-E. The MODE assignment specifies read/write permissions.

   

After adding these line,now execute: chmod a+r /etc/udev/rules.d/51-android.rules

5.Exit from Root as well as terminal.


6. Now execute this inside your terminal:
   adb kill-server
   sudo adb start-server
   adb devices



Wednesday, 3 December 2014

Difference Between HVGA and Display QVGA in Android


Difference Between HVGA and QVGA Display.

All of you probably already know the mean of HVGA and QVGA screen. But may not know what the differentiates the screen display.

QVGA or Quick Video Graphics Adapter, is a screen that has a resolution of 240 x 320 Pixel. While HVGA or Hight Video Graphics Adapter is a screen that has a resolution of 320 x 480 px.

Well,from the size of the resolution HVGA screen size we can see if it is much larger than QVGA. not only that, no matter if HVGA resolution is sharper at HVGA appeal. But besides that, phones with HVGA screens tend to be more wasteful of energy because of the huge resolution.

Differences in screen resolution is also give impact on applications that can run, such as games. there is a different kinds of games for HVGA and QVGA screen. So if you want to install games on android, make sure the games are compatible with its resolution or not.

Tuesday, 18 November 2014

JSOUP Example Android

JSOUP Implementation for Android.

Basic Ideas about JSOUP:
JSOUP is a Java library for working with real-world HTML. It provides a very convenient API for extracting and manipulating data, using the best of DOM, CSS, and jquery-like methods.JSOUP implements the WHATWG HTML5 specification, and parses HTML to the same DOM as modern browsers do.
JSOUP allows you to scrape and parse HTML from a URL, file, or string and many more.

Before Starting development, Download JSOUP form this URL: http://jsoup.org/download


Now Create a New Android Project. Here I am creating a new project named "TestJSOUP".
In that project, you must have to put jsoup rar file inside your libs folder.
After copying file, you have to build path inside your project,rightclick on jsoup.rar->Buildpath->Add to Build Path.

Our Main intensity of this project is get Title, Document name and image. Here for example I am taking one website "http://www.dreamstime.com/" and
fetching the data.
We can get the title by using document.title().
Just Write Down this bellow code and execute this in your system.

activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/btn_title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="website title" />
    <ImageView
        android:id="@+id/img"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

    <TextView
        android:id="@+id/tv_details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Medium Text"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

MainActivity.java
public class MainActivity extends ActionBarActivity {

String url = "http://www.dreamstime.com/";

Button wbTitle;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wbTitle = (Button)findViewById(R.id.btn_title);
img = (ImageView)findViewById(R.id.img);

wbTitle.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
new Title().execute();
}
});
}

private class Title extends AsyncTask<Void, Void, Void>{

ProgressDialog pd;
String title;

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pd = new ProgressDialog(MainActivity.this);
pd.setTitle("Loading Your Page");
pd.setMessage("Loading...");
            pd.setIndeterminate(false);
            pd.show();
}

@Override
protected Void doInBackground(Void... arg0) {
try {
Document document = Jsoup.connect(url).get();
title = document.title();
Elements elem = document.select("meta[name=description]");
Elements img = document.select("a[id=frontLink] img[src]");
String descriptionContent = elem.attr("content");
String imgPath = img.attr("src");
System.out.println("ttitle:"+title);
System.out.println("Description: "+descriptionContent);
System.out.println("ImagePath=>"+imgPath);
System.out.println("iimmgg:"+img);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
TextView txttitle = (TextView) findViewById(R.id.tv_details);
            txttitle.setText(title);
pd.dismiss();
}

}

}


Monday, 27 October 2014

Set values to Dimen folder for different screen of Android

List for all resolution support:
Android Device

For 10.1" Tablet:
values-sw720dp  10.1” tablet 1280x800 mdpi
For 7" Tablet:
values-sw600dp  7.0”     tablet 1024x600 mdpi

values-sw480dp      5.4” 480x854 mdpi
values-sw480dp      5.1” 480x800 mdpi

values-xhdpi          4.7”   1280x720 xhdpi
values-xhdpi          4.65” 720x1280 xhdpi

values-hdpi            4.0” 480x800 hdpi
values-hdpi            3.7” 480x854 hdpi

values-mdpi           3.2” 320x480 mdpi

values-ldpi             3.4” 240x432 ldpi
values-ldpi             3.3” 240x400 ldpi
values-ldpi             2.7” 240x320 ldpi

Tuesday, 26 August 2014

Different Screen Resolution Devices Android


Different Screen Resolution Devices Android

When you develop an application, your main intensity to support in multiple screens which will fit your screen. Before developing any application, you must need to know screen resolution. I am providing you a list, which will help you to understand more.






Saturday, 12 July 2014

Tips To Create A Great Splash Screen For Your Mobile Application

Splash Screen For Your Mobile Application


When you create your app for iPhone, Android, or any other platform, you must add a killer splash screen if you want to ensure a good launch experience for your users.
The splash screen is the first image that is seen when your app is opened. Let's review some tips that will help you to succeed in creating it.

1.Use the right size
From a smartphone to another, the screen's resolution can vary a lot.

Let's imagine you have crafted the perfect splash screen for an iPhone 5S. This image  should mesure 640 x 1136px. It will look great on the iPhone 5S, 5C and 5, which have the same screen resolution. But what about the iPhone 4 which has a 640 x 960 px screen resolution? Displayed on the iPhone 4S or 4, your splash screen will be distorted.

To make the perfect one, you should create as much splash screens as there are screen resolutions. If your are creating an iPhone app, it's not a big deal since there are few devices.

But, if you build an Android app, it's far more complicated. There are lot of manufacturers, a lot of devices ... implying a lot of screen resolutions. It would be crazy to embed in your Android app dozens of splash screens to handle all the existing resolutions on Android devices.
The best way to deal with this problem is to create 3 splash screens.  A small, a medium and a high res, and pull the one that is the closest to the screen resolution of the phone that opens the app. To quickly make those 3 images, read next tip.

2.Keep it simple

The splash screen doesn't last very long. So no need to put a long text on your splash screen. Your users won't have the time to read it. And moreover, that's not the purpose of the splash screen.
Use your brand name, your logo, your motto, or whatever that describes you and your app the best. Make a clear composition using those elements, and create one single image, in portrait mode.

If you want to create several sizes of your splash screen, I recommend you to focus on the center of the image to put your composition. Leaving the edges of the splash screen free will enable you to crop your image to the different desired sizes.



3.Tell your users it's loading

The splash screen is a still image. When you see it, it looks like your phone is frozen. Nothing happens. You can't interact with the app. You're stuck. You can only wait for the app to finish its loading.

A lot of things can happen in the background when your app is being launched. Your app may need to upload or download data before being ready to be used. Your app launches some processes to boot correctly a new session or restore an old one ... well, depending the user's phone processor and/or the bandwidth the phone has access to, the time to boot your app can vary a lot.

To reassure your users, you should mention in your splash screen that your app is loading, and that within a few seconds of patience, your user will be able to use and enjoy your app.


Thursday, 26 June 2014

How to create standard Borderless buttons in Android??



Basically it can done in Two Steps:

Step1:
   Setting the button background attribute to android:attr/selectableItemBackground creates you a button with feedback but no background. SO you need to write like this(In xml):

   android:background="?android:attr/selectableItemBackground"

Step2: 
  The line to divide the borderless button from the rest of you layout is done by a view with the background android:attr/dividerVertical

   android:background="?android:attr/dividerVertical"


 Before applying logic your code will look like this in xml file:

 <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:gravity="left|center_vertical"
        android:text="Button" />




<Button
        android:id="@+id/btn_home"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:layout_marginTop="10dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:background="?android:attr/selectableItemBackground"
        android:gravity="left|center_vertical"

        android:text="Button" />

After applying above logic:






Thursday, 30 January 2014

XML Parsing in Android

XML Parsing in Android Using DOM

What is an XML(Extensible Markup Language)?
Ans:  XML stands for Extensible Markup Language.XML was defined by W3C(World Wide Web Consortium).
An XML document consists of elements, each element has a start tag and an end tag,in between that content will be there.An XML file must be "well-formed".An XML file is called valid if it is well-formed.
An Well-formed xml look like bellow:
<?xml version="1.0"?>
<car>
  <name>BMW</name>
  <cost>2500000</cost>
</car>
XML Parsers in Android
Android supports two types of XML Parsers:
      1.    DOM(Document Object Model) Parser
      2.    SAX(Simple API for XML) Parser
 In this tutorial we will see how DOM(Document Object Model) parsing hapenning in android. To parse the xml file, we need xml data. So at first we will create a xml file, then we will parse it in our android device.
To Create XML file, see bellow steps:
Go to your Notepad application, Type the following code:

<?xml version="1.0"?> 
<computers> 
<brand> 
    <name>Apple</name> 
    <cost>45000</cost> 
</brand> 
<brand> 
     <name>Dell</name> 
     <cost>40000</cost> 
</brand> 
<brand> 
     <name>HP</name> 
     <cost>35000</cost> 
</brand> 
</computers>  

Then go File-> Save as -> testxml.xml.

After generating  this xml file, put this xml file Under assets folder in your android project.See Bellow how it will look like:


Creating Android Application Project for XML Parsing:
In Eclipse -> Create New Project(Named as TestDomParser). -> Provide Activity Name(Here name as MainActivity). This application building Android Version 4.2.2, API level 17.
MainActivity.java will look like this:
public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TextView tv_parse =(TextView)findViewById(R.id.tv);
        try{
            InputStream is = getAssets().open("testxml.xml");
            DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder dbBuilder = dbFactory.newDocumentBuilder();
            Document doc = dbBuilder.parse(is);
           
            Element element=doc.getDocumentElement(); 
            element.normalize();
           
            NodeList nList = doc.getElementsByTagName("brand");
            for (int i=0; i<nList.getLength(); i++) { 
                        Node node = nList.item(i); 
                        if (node.getNodeType() == Node.ELEMENT_NODE) { 
                                    Element elmnt = (Element) node; 
                                    tv_parse.setText(tv_parse.getText()+"\nCompany Name: " +                                                             getValue("name", elmnt)+"\n"); 
                                    tv_parse.setText(tv_parse.getText()+"Price: " + getValue("cost",                                                     elmnt)+"\n"); 
                                    tv_parse.setText(tv_parse.getText()+"**********************"); 
                                    } 
            }
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    private static String getValue(String tag, Element element) { 
            NodeList nodeList = element.getElementsByTagName(tag).item(0).getChildNodes(); 
            Node node = (Node) nodeList.item(0); 
            return node.getNodeValue(); 
            } 
   
}

Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/tv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:textStyle="bold"
        android:textSize="15sp"
        android:layout_marginLeft="16dp"
        android:layout_marginTop="14dp"
        android:text="" />

</RelativeLayout>

Result:


Wednesday, 1 January 2014

Android JSON Parsing Using Async Task

JSON Parsing in Android using Asynctask

In Previous tutorial, mentioned about JSON types and how JSON parsing is happening without using asynctask. In this tutorial, I will talk about JSON parsing using Asynctask.  

What is Async Task?
 AsyncTask enables proper and easy use of the UI thread.This class allows to perform  background operations and publish results on the UI thread.

Async Task has Four Operations:
         1. onPreExecute()- It invoked before execution.
         2. onPostExecute()- It invoked after execution.
         3. doInBackground()- Main operation, write your long operation code.
         4. onPregressUpdate()- It indicates user on progress.

Async Task has Three generic types:

AsyncTask<Param, Progress, Result>
AsyncTask<{Type of Input},{Type of Update Unit},{Type of Update Result}>



In this tutorial, I am taking an example of following JSON which will give you list of News and each “NewsLines” have different Head-Lines and Date-Lines. You can get this JSON by accessing  http://mfeeds.timesofindia.indiatimes.com/Feeds/jsonfeed?newsid=3947071&amp;amp;format=simplejson


If you observe carefully, you can see { and ]. The main difference between these two is object and array. Curly bracket { represents JSONObject and Square bracket [ represents JSONArray.



In this example, I will create a button and after clicking on button the data will show in listview. So our main.xml will be like this:
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/getdata"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="14dp"
        android:text="Get Data" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/getdata"
        android:layout_centerHorizontal="true" >

    </ListView>

</RelativeLayout>

Now we will create Parser class. This parser class is used to execute the JSON link and get the JSON data and returns JSON Object.

public class Parser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";
    public JSONObject getJSONData(String url){
            try{
                        DefaultHttpClient client = new DefaultHttpClient();
                        HttpPost post = new HttpPost(url);
                        HttpResponse response = client.execute(post);
                        HttpEntity entity = response.getEntity();
                        is = entity.getContent();
            }catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
            try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(
                    is, "iso-8859-1"), 8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            is.close();
            json = sb.toString();
        } catch (Exception e) {
            Log.e("Buffer Error", "Error converting result " + e.toString());
        }
            try {
            jObj = new JSONObject(json);
        } catch (JSONException e) {
            Log.e("JSON Parser", "Error parsing data " + e.toString());
        }
        return jObj;
    }
}

In NewsLines, there are multiple strings i.e HeadLine and DateLine. So you need to define these in your MainActivity class.
    private static final String NEWS = "NewsML";
        private static final String NEWS_LINE = "NewsLines";
        private static final String HEAD_LINE = "HeadLine";
        private static final String DATE_LINE = "DateLine";
After button click, it will execute AsyncTask, so you need to write like this way:

Btngetdata.setOnClickListener(new OnClickListener() {
                                   
                                    @Override
                                    public void onClick(View v) {
                                                new JSONParse().execute();
                                    }
                        });


Here JSONParse is a class for Asynctask operation.By using this JSONParse class, it will get the data and fill in the list view. So JSONPasre class will look like this:

private class JSONParse extends AsyncTask<String, Integer, ArrayList<HashMap<String, String>>>{


  
ArrayList<HashMap<String, String>> newsList = new ArrayList<HashMap<String, String>>();

                        
        private ProgressDialog pDialog;
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(MainActivity.this);
            pDialog.setMessage("Loading Data ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }


                        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(String... params) {

             Parser jParser = new Parser();
            JSONObject json = jParser.getJSONData(url);
            try{
                        news = json.getJSONArray(NEWS);
                        for(int i=0;i<news.length();i++){
                                    JSONObject object = news.getJSONObject(i);
                                    JSONObject newsline = object.getJSONObject(NEWS_LINE);
                                    String headLine = newsline.getString(HEAD_LINE);
                                    String dateLine = newsline.getString(DATE_LINE);
                                    HashMap<String, String> map = new HashMap<String, String>();
                                    map.put(HEAD_LINE, headLine);
                                    map.put(DATE_LINE, dateLine);
                                    newsList.add(map);
                        }
            }catch(JSONException e){
                        e.printStackTrace();
            }
            return newsList;
           }//Ending doInBackground


                        @Override
           protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

                                    super.onPostExecute(result);
                                    pDialog.dismiss();
                                    String []from = {HEAD_LINE,DATE_LINE};
                                    int []to = {R.id.tv_headLn,R.id.tv_dateLn};
                                    ListAdapter adapter = new SimpleAdapter(MainActivity.this, result,R.layout.listview_item, from, to);
                                    setListAdapter(adapter);
                        }


So the MainActivity class will look like this:

MainActivity.java

public class MainActivity extends ListActivity {

    Button Btngetdata;
    private static final String NEWS = "NewsML";
    private static final String NEWS_LINE = "NewsLines";
    private static final String HEAD_LINE = "HeadLine";
    private static final String DATE_LINE = "DateLine";
    JSONArray news = null;
    //URL to get JSON Array
    private static String url = "http://mfeeds.timesofindia.indiatimes.com/Feeds/jsonfeed?newsid=3947071&amp;amp;format=simplejson";

            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        requestWindowFeature(Window.FEATURE_NO_TITLE);
                        setContentView(R.layout.activity_main);
                        Btngetdata = (Button)findViewById(R.id.getdata);
                        Btngetdata.setOnClickListener(new OnClickListener() {
                                   
                                    @Override
                                    public void onClick(View v) {
                                                new JSONParse().execute();
                                    }
                        });
            }

        private class JSONParse extends AsyncTask<String, Integer, ArrayList<HashMap<String, String>>>{

ArrayList<HashMap<String, String>> newsList = new ArrayList<HashMap<String, String>>();


            private ProgressDialog pDialog;

            protected void onPreExecute() {

            super.onPreExecute();
            pDialog = new ProgressDialog(MainActivity.this);
            pDialog.setMessage("Loading Data ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }

                        @Override
        protected ArrayList<HashMap<String, String>> doInBackground(String... params) {

             Parser jParser = new Parser();
            JSONObject json = jParser.getJSONData(url);
            try{
                        news = json.getJSONArray(NEWS);
                        for(int i=0;i<news.length();i++){
                                    JSONObject object = news.getJSONObject(i);
                                    JSONObject newsline = object.getJSONObject(NEWS_LINE);
                                    String headLine = newsline.getString(HEAD_LINE);
                                    String dateLine = newsline.getString(DATE_LINE);
                                    HashMap<String, String> map = new HashMap<String, String>();
                                    map.put(HEAD_LINE, headLine);
                                    map.put(DATE_LINE, dateLine);
                                    newsList.add(map);
                        }
            }catch(JSONException e){
                        e.printStackTrace();
            }
            return newsList;
         }
                        @Override
        protected void onPostExecute(ArrayList<HashMap<String, String>> result) {

                                    
                                    super.onPostExecute(result);
                                    pDialog.dismiss();
                                    String []from = {HEAD_LINE,DATE_LINE};
                                    int []to = {R.id.tv_headLn,R.id.tv_dateLn};
                                    ListAdapter adapter = new SimpleAdapter(MainActivity.this, result, R.layout.listview_item, from, to);
                                    setListAdapter(adapter);

                        }
                       
            }
}

Result: