HttpURLConnection not fetching data and displaying the result in ListView - android

I have this code that I am trying to run after making all kinds of changes to it. The problem is that i have added permissions and added still find that the code seems to be not working.
It would be a great help if anyone can help me find my mistake.
Where am I going wrong.
This is the .java file.
package com.example.adityapc.phpfeeddisplay;
import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ActivityMain extends Activity {
private static final String TAG = "Http Connection";
private ListView listAct = null;
private ArrayAdapter arrayAdapter = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listAct = (ListView) findViewById(R.id.listActivity);
final String url = "http://anonymoous.marshalcadetacademy.com/notification.php";
new AsyncHttpTask().execute(url);
}
public class AsyncHttpTask extends AsyncTask<String, Void, Integer> {
#Override
protected Integer doInBackground(String... params) {
InputStream inputStream = null;
HttpURLConnection urlConnection = null;
Integer result = 0;
try {
URL url = new URL(params[0]);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestProperty("Content-Type", "application/json");
urlConnection.setRequestProperty("Accept", "application/json");
urlConnection.setRequestMethod("GET");
int statusCode = urlConnection.getResponseCode();
if (statusCode == 200) {
inputStream = new BufferedInputStream(urlConnection.getInputStream());
String response = convertInputStreamToString(inputStream);
parseResult(response);
result = 1;
}else{
result = 0;
}
}
catch (Exception e) {
Log.d(TAG, e.getLocalizedMessage());
}
return result;
}
#Override
protected void onPostExecute(Integer result) {
if(result == 1){
arrayAdapter = new ArrayAdapter(ActivityMain.this, android.R.layout.simple_list_item_1,R.id.listActivity);
listAct.setAdapter(arrayAdapter);
}
else{
Log.e(TAG, "Failed to fetch data!");
}
}
}
private String convertInputStreamToString(InputStream inputStream) throws IOException {
BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(inputStream));
String line = "";
String result = "";
while((line = bufferedReader.readLine()) != null){
result += line;
}
if(null!=inputStream){
inputStream.close();
}
return result;
}
private void parseResult(String result) {
try{
JSONObject response = new JSONObject(result);
JSONArray posts = response.optJSONArray("posts");
String[] blogTitles = new String[posts.length()];
for(int i=0; i< posts.length();i++ ){
JSONObject post = posts.optJSONObject(i);
String title = post.optString("title");
blogTitles[i] = title;
}
}catch (JSONException e){
e.printStackTrace();
}
}
}
And here is the .xml code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/linear" >
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="#+id/listActivity"
android:layout_gravity="center">
</ListView>
</LinearLayout>
If you all have any suggestions to make, your help will be appreciated.

Related

How Can I Print Data From Database In TableView?

I want to Print My data from database In form of TableView How do I print data.
Database i used is SQLite.
Just take data from your API or service Inform of JSON and follow the below reference.
Answer ref
make a file fetchData.java
import android.os.AsyncTask;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class fetchData extends AsyncTask<Void,Void,Void> {
String data ="";
String dataParsed = "";
String singleParsed ="";
#Override
protected Void doInBackground(Void... voids) {
try {
URL url = new URL("https://api.myjson.com/bins/107msz");
HttpURLConnection httpURLConnection = (HttpURLConnection)
url.openConnection();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(inputStream));
String line = "";
while(line != null){
line = bufferedReader.readLine();
data = data + line;
}
JSONArray JA = new JSONArray(data);
for(int i =0 ;i <JA.length(); i++){
JSONObject JO = (JSONObject) JA.get(i);
singleParsed = "Name:" + JO.get("name") + "\n"+
"Password:" + JO.get("password") + "\n";
dataParsed = dataParsed + singleParsed +"\n" ;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
MainActivity.data.setText(this.dataParsed);
}
}
Another file MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button click;
public static TextView data;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
click = (Button) findViewById(R.id.button);
data = (TextView) findViewById(R.id.fetcheddata);
click.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
fetchData process = new fetchData();
process.execute();
}
});
}
}
In your Activity_main.xml write this code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.abhishekpanwar.receivedatajson.MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me!"
android:layout_marginBottom="10dp"
android:id="#+id/button"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/button">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="5dp"
android:textSize="40sp"
android:id="#+id/fetcheddata"
android:fontFamily="sans-serif"
android:hint="Fetched Text Here!!!"/>
</ScrollView>
</RelativeLayout>

get JSON Array from local server in android 6.0 with HttpURLConnection

I am trying to get a JSON Array from this local server for five days:
localhost/match_picture/service.php?action=read
and i can't do it !!
I search it in google and read too many documentations !
here is my code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class WebService {
public static String readUrl(String server_url) {
BufferedReader bufferedReader = null;
try {
URL url = new URL(server_url);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
StringBuilder sb = new StringBuilder();
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json;
while ((json = bufferedReader.readLine()) != null) {
sb.append(json+"\n");
}
return sb.toString();
}catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
and it's Main_Activity:
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class Activity_main extends AppCompatActivity {
private ArrayList<StructAcount> netAcount = new ArrayList<StructAcount>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
String result= WebService.readUrl("http://localhast/match_picture/service.php?action=read");
if (result != null) {
try {
JSONArray tasks = new JSONArray(result);
for (int i=0; i<tasks.length(); i++) {
StructAcount acount= new StructAcount();
JSONObject object = tasks.getJSONObject(i);
acount.id = object.getLong("user_id");
acount.name = object.getString("user_name");
acount.email = object.getString("user_email");
netAcount.add(acount);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
for (StructAcount acount: netAcount) {
Toast.makeText(Activity_main.this, "username: " + acount.name + "\n" + "useremail: " + acount.email , Toast.LENGTH_SHORT).show();
}
}
}
it is runing on emulator and crashes in this line:
bufferedReader = new BufferedReader(new InputStreamReader(con.getInputStream()));
and i dont know why ...
I am Searching for five days!!!!
I can do it with HttpClient
but i want to be update
I saw a vidoe in youtube that create a class in Main_Activity extends AsyncTask and make connenction in doInBackground(String... params). I try that and that works correcly. but because I want to do it in anoder class (WebService) and I dont know how can i sent result to Main_Activity , I remove that class extended from AsyncTask.
thank's for your help
sorry for my poor english
You have a NetworkOnMainThreadException to begin with.
And your app crashes.
Google how to solve it.

I have to add edittext input at city position and add it to url

/* Here the last parameter is taken from edittext but it is not adding input from
edittext */ Please check:
http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo/CBS/NOIDA/ADMIN
package com.example.administrator.spinnerval;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class SalesActivity extends AppCompatActivity {
StringBuffer buffer = new StringBuffer();
List<String> salesPeName = new ArrayList<String>();
HttpURLConnection connection;
BufferedReader reader;
ProgressDialog pdLoading;
String username = "CBS";
String password = "NOIDA";
String city="" ;
String myurl;
ArrayAdapter adapter;
URL url;
AutoCompleteTextView acTextView;
//String url="http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo/";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sales);
acTextView = (AutoCompleteTextView) findViewById(R.id.autoComplete2);
acTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selection = (String)parent.getItemAtPosition(position);
// city=(String)parent.getItemAtPosition(position);
city=acTextView.getText().toString();
}
});
myurl="http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo";
String res = new StringBuilder(14).append(myurl).append("/").append(username).append("/").append(password).toString();
String result=new StringBuilder(14).append(res).append("/").append(city).toString();
try {
url=new URL(result);
Log.d("url",url.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
}
adapter = new
ArrayAdapter(this, android.R.layout.simple_list_item_1, salesPeName);
//acTextView.setAdapter(adapter);
new SalesTask().execute(city);
}
private class SalesTask extends AsyncTask<String,String,String> {
#Override
protected String doInBackground(String... params) {
try {
//url = new URL("http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo/"+username+"/"+password+"/"+city);
connection = (HttpURLConnection) url.openConnection();
Log.e("url reference value",url.toString());
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
String line = "";
Log.d("bufferData", buffer.toString());
while ((line = reader.readLine()) != null) {
buffer.append(line);
}
return buffer.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (connection != null) {
connection.disconnect();
}
try {
if (reader != null) {
reader.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
String jsonString = buffer.toString();
// Log.e("Final Json that we have", jsonString);
JSONObject obj = null;
try {
obj = new JSONObject(jsonString);
JSONObject obj1 = obj.getJSONObject("GetBPSalesPersonResult");
JSONArray jArray = obj1.getJSONArray("BPResult");
for (int i = 0; i <= jArray.length(); i++) {
salesPeName.add(jArray.getJSONObject(i).getString("SALES_PERSON_NO"));
Log.e("Location",salesPeName.toString());
acTextView.setAdapter(adapter);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
}
Logcat is printing url as :
url: http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo/CBS/NOIDA/
Not sure if I understood your question correctly, but you are adding undeclared variables to the url. I think it should be:
URL url = new URL("http://103.75.33.98/BPService/GetAllBPService.svc/GetSalesPersonNo/"+cbs+"/"+city+"/"+saleP);
The problem is that you create the Url on in onCreate, at witch time city="", and you change the city in onItemClick: city=acTextView.getText().toString(), you need to generate the URL in onItemClick and call new SalesTask().execute(city); not right away
acTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String selection = (String)parent.getItemAtPosition(position);
city = acTextView.getText().toString();
url = new URL(new StringBuilder(myurl).append("/").append(username).append("/").append(password).append("/").append(city).toString());
new SalesTask().execute(city);
}
});

Android:Dynamically changing the height of the image view according to the received json data

I am accessing a mysql database table to show the tank level .I need to display the value in an image view using a rectangle.Each time value of the level changes I need to change the height of the rectangle.How is it possible in android.In the below code container 1 and container 2 is the variable which stores the level data.How to access this data and change the height of the image view.
package com.example.tg.mysmartcontainer;
import android.os.AsyncTask; import android.os.Bundle; import
android.support.v7.app.ActionBarActivity; import
android.widget.ListAdapter; import android.widget.ListView; import
android.widget.SimpleAdapter; import android.os.Handler; import
org.apache.http.HttpEntity; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost; import
org.apache.http.impl.client.DefaultHttpClient; import
org.apache.http.params.BasicHttpParams; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONObject;
import java.io.BufferedReader; import java.io.InputStream; import
java.io.InputStreamReader; import java.util.ArrayList; import
java.util.HashMap;
public class MainActivity extends ActionBarActivity {
String myJSON;
Handler mHandler;
private static final String TAG_RESULTS = "result";
private static final String TAG_timeStamp = "timeStamp";
private static final String TAG_container1 = "container1";
private static final String TAG_container2 = "container2";
JSONArray container = null;
ArrayList<HashMap<String, String>> ContainerList;
ListView list;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list = (ListView) findViewById(R.id.listView);
ContainerList = new ArrayList<HashMap<String, String>>();
final Handler handler = new Handler();
Runnable refresh = new Runnable() {
#Override
public void run() {
getData();
handler.postDelayed(this, 0);
}
};
handler.postDelayed(refresh, 0);
//getData();
}
public void getData() {
class GetDataJSON extends AsyncTask<String, Void, String> {
#Override
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://smartgrocer.000webhostapp.com/get_data.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
// json is UTF-8 by default
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
// Oops
} finally {
try {
if (inputStream != null) inputStream.close();
} catch (Exception squish) {
}
}
return result;
}
#Override
protected void onPostExecute(String result) {
myJSON = result;
showList();
}
}
GetDataJSON g = new GetDataJSON();
g.execute();
}
protected void showList() {
try {
JSONObject jsonObj = new JSONObject(myJSON);
container = jsonObj.getJSONArray(TAG_RESULTS);
if(ContainerList!=null&&ContainerList.size()>0)
ContainerList.clear();
for (int i = 0; i < container.length(); i++) {
JSONObject c = container.getJSONObject(i);
String timeStamp = c.getString(TAG_timeStamp);
String container1 = c.getString(TAG_container1);
String container2 = c.getString(TAG_container2);
HashMap<String, String> container = new HashMap<String, String>();
container.put(TAG_timeStamp, timeStamp);
container.put(TAG_container1, container1);
container.put(TAG_container2, container2);
ContainerList.add(container);
}
ListAdapter adapter = new SimpleAdapter(
MainActivity.this, ContainerList, R.layout.list_item,
new String[]{TAG_timeStamp, TAG_container1, TAG_container2},
new int[]{R.id.timeStamp, R.id.container1, R.id.container2}
);
list.setAdapter(adapter);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
to set the height of the ImageView:
image_view.getLayoutParams().height = 20;
Hope this helps.
Important. If you're setting the height after the layout has already been 'laid out', make sure you also call:
image_view.requestLayout()
Change the height of the imageView according to the current value :
tankImageView.setHeight((int)(currentValue / maxValue));

Download images from remote URLs

Currently I am developing an Android app containing a list view which displays links for Youtube videos. The application gets its data from the server as JSON. Now I am trying to display thumbnails for these video from this subdomain - http://img.youtube.com/vi/.
But the images don't show up in the list view.
Here is the code for the project :
1 - canticlesActivity.java
package com.shadatv.shada;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.ListActivity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class canticlesActivity extends ListActivity {
TextView httpStuff;
HttpClient client;
JSONArray canticles;
String picpath = "http://img.youtube.com/vi/";
File sdcard = Environment.getExternalStorageDirectory();
File shadaRoot = new File(sdcard.getAbsolutePath() + "/shada_Folder");
private static final String CA_NAME = "ca_name";
private static final String CA_LINK = "ca_link";
private static final String CA_IMG = "ca_img";
private static final String URL = "http://dt-works.com/ags/shadatv/canticles/android_data";
ArrayList<HashMap<String, String>> canticlesList;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.canticles);
httpStuff = (TextView) findViewById(R.id.textView1);
client = new DefaultHttpClient();
new Read().execute();
}
public JSONArray allCanticles() throws ClientProtocolException, IOException, JSONException {
StringBuilder url = new StringBuilder(URL);
HttpGet get = new HttpGet(url.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity e = r.getEntity();
String data = EntityUtils.toString(e);
JSONArray canticles = new JSONArray(data);
return canticles;
} else {
Toast.makeText(getBaseContext(), "error", Toast.LENGTH_SHORT).show();
return null;
}
}
public void downloadImage(String fileURL) {
try {
// Toast.makeText(getBaseContext(), "baaad", Toast.LENGTH_SHORT).show();
String finlpth = "";
finlpth = picpath + fileURL + "/2.jpg";
shadaRoot.mkdirs();
URL u = new URL(finlpth);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
File DownloadedFile = new File(shadaRoot, fileURL + ".jpg");
// if(!outfile.exists())
FileOutputStream f = new FileOutputStream(DownloadedFile);
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
f.write(buffer, 0, len1);
}
f.close();
} catch (Exception e) {
Log.d("Downloader", e.getMessage());
}
}
public class Read extends AsyncTask<String, String, String>{
#Override
protected String doInBackground(String... params) {
canticlesList = new ArrayList<HashMap<String, String>>();
try {
canticles = allCanticles();
for (int i = 0; i < canticles.length(); i++) {
JSONObject canticle = canticles.getJSONObject(i);
String ca_name = canticle.getString(CA_NAME);
String ca_link = canticle.getString(CA_LINK);
downloadImage(ca_link);
HashMap<String, String> map = new HashMap<String, String>();
map.put(CA_NAME, ca_name);
map.put(CA_LINK, ca_link);
map.put(CA_IMG, ca_link + ".jpg");
canticlesList.add(map);
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
#Override
protected void onPostExecute(String result) {
ListAdapter adapter = new SimpleAdapter(canticlesActivity.this,
canticlesList,R.layout.list_item,
new String[] {CA_NAME, CA_LINK, CA_IMG},
new int[] {R.id.ca_name, R.id.ca_link, R.id.ca_img});
setListAdapter(adapter);
}
}
}
2 - list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/list_selector"
android:orientation="horizontal" >
<!-- Product id (pid) - will be HIDDEN - used to pass to other activity -->
<ImageView
android:id="#+id/ca_img"
android:layout_width="50dip"
android:layout_height="50dip"
android:contentDescription="#string/desc"
/>
<TextView
android:id="#+id/ca_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<!-- Name Label -->
<TextView
android:id="#+id/ca_link"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="6dip"
android:paddingLeft="6dip"
android:textSize="17sp"
android:textStyle="bold"
android:visibility="gone" />
</LinearLayout>
You can use UniversalImageLoader
it very simple for using -imageLoader.displayImage(imageUri, imageView);
Downloading images and then displaying in ListView is bad process. Because just think if you are having >100 images then it will take more time to display it.
And now optimization which i would suggest is: Implement logic for lazy loading of Images inside ListView.
Refer below examples:
Lazy List by Fedor
Universal Image Loader
ImageLoader by Novoda
In youtube JSON data ,The entire videos information will be in "entry" JSON array. You are creating same tag name for all the entires in the Hashmap.. If you give same tag for all entries then it will display last entry image. Please change the TAG NAME to "map.put(CA_IMG+i, ca_link + ".jpg");"
I hope this solution will be helpful for you.

Categories

Resources