So far I have done this much. Will you please help me what to do next to load an image in a listview. I have parsed url using xml parsing. I just want to load an image in a listview. Please help me experts!!
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
Bundle b = getIntent().getExtras();
m_brandName = b.getString("Brand_Name");
m_modelName = b.getString("Model_Name");
m_categoryName = b.getString("Category_Name");
actAppChartCatList = this;
//String url = "http://www.bitstechnologies.in/HellaWebserviceV2/Service1.asmx/populateBrandModelCategory?brandName=\" + m_brandName + \"&\" + \"modelName=\" + m_modelName + \"&\" + \"categoryName=\" + m_categoryName";
String url = "http://www.bitstechnologies.in/HellaWebserviceV2/Service1.asmx/populateBrandModelCategory?brandName=" + m_brandName + "&modelName=" + m_modelName + "&categoryName=" + m_categoryName;
String urlFinal = "";
if (url.contains(" "))
urlFinal = url.replace(" ", "%20");
else
urlFinal = url;
//new DownloadTaskCV().execute("http://www.bitstechnologies.in/HellaWebserviceV2/Service1.asmx/populateBrandModelCategory?brandName=" + m_brandName + "&" + "modelName=" + m_modelName + "&" + "categoryName=" + m_categoryName);
new DownloadTaskCV().execute(urlFinal);
pdGettingProducts = ProgressDialog.show(ActivityAppChartToCategoryList.this, "", "Getting Products.......");
setContentView(R.layout.activity_activity_app_chart_to_category_list);
mListView = (ListView) findViewById(R.id.showProductLists);
}
public static ActivityAppChartToCategoryList getInstance() {
return actAppChartCatList;
}
public void progDialogDownloadingDismiss() {
if (pdGettingProducts != null) {
pdGettingProducts.dismiss();
}
}
public void showEmptyMessage() {
progDialogDownloadingDismiss();
adb = new AlertDialog.Builder(this);
adb.setTitle("");
adb.setMessage("No products");
adb.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onBackPressed();
}
});
adb.show();
}
/*
* A method to download json data from url
*/
private String downloadUrl(String strUrl) throws IOException {
String data = "";
InputStream iStream = null;
try {
URL url = new URL(strUrl);
// Creating an http connection to communicate with url
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
// Connecting to url
urlConnection.connect();
Log.e("Response code : ", "" + urlConnection.getResponseCode());
// Reading data from url
iStream = urlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(iStream));
StringBuffer sb = new StringBuffer();
String line = "";
while ((line = br.readLine()) != null) {
sb.append(line);
}
data = sb.toString();
br.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
iStream.close();
}
//pdDownloadingList.dismiss();
return data;
}
private class DownloadTaskCV extends AsyncTask<String, Integer, String> {
String data = null;
Product product = null;
ArrayList<Product> productslist = null;
@Override
protected String doInBackground(String... url) {
try {
data = downloadUrl(url[0]);
} catch (Exception e) {
e.printStackTrace();
}
return data;
}
@Override
protected void onPostExecute(String result) {
//super.onPostExecute(result);
try {
if ((result.equalsIgnoreCase("[]")) || (result == null)) {
showEmptyMessage();
this.cancel(true);
}
parseXmlResponse(result);
} catch (Exception e) {
showEmptyMessage();
this.cancel(true);
}
}
private String parseXmlResponse(String xmlResponse) {
if (xmlResponse != null) {
XmlPullParser myParser;
XmlPullParserFactory xmlFactoryObject;
try {
xmlFactoryObject = XmlPullParserFactory.newInstance();
myParser = xmlFactoryObject.newPullParser();
myParser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
int event;
String text = null;
event = myParser.getEventType();
while (event != XmlPullParser.END_DOCUMENT) {
String name = myParser.getName();
switch (event) {
case XmlPullParser.START_TAG:
if (name.equalsIgnoreCase("ProductList")) {
// instantiate Arraylist of "Products"
productslist = new ArrayList<>();
}
if (name.equalsIgnoreCase("Product_Name")) {
// instantiate object of Product
product = new Product();
}
break;
case XmlPullParser.TEXT:
text = myParser.getText();
break;
case XmlPullParser.END_TAG:
if (name.equalsIgnoreCase("Product_Name")) {
// prodObj.setProductName(text)
product.setProducts_name(text);
}
if (name.equalsIgnoreCase("Product_Image_Left")) {
// prodObj.setProductImageLeft(text)
product.setProducts_image(text);
// add the product object to the array List
productslist.add(product);
}
break;
default:
break;
} // end of switch
event = myParser.next();
}
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return xmlResponse;
}
}