I am new in android programming. so i need help on the issue which i am facing. Actually i am getting data from magento in android app using eclipse. i am using simple adapter for displaying text and images in listview. text data is perfectly displayed in listview but i am getting problem with displaying images in listview.What i have done is for displaying images is:- MainActivity.java class
public class MainActivity extends Activity {
private static final String NAMESPACE = "urn:Magento";
private static final String URL = "url of magento";
Bitmap bitmap;
URL imageURL = null;
ArrayList<Bitmap> bitmapArray = new ArrayList<Bitmap>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
TextView tv1 = (TextView) findViewById(R.id.tv);
ListView lv = (ListView) findViewById(R.id.lv);
ImageView image_view = (ImageView)findViewById(R.id.imageview);
try {
SoapSerializationEnvelope env = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
env.dotNet = false;
env.xsd = SoapSerializationEnvelope.XSD;
env.enc = SoapSerializationEnvelope.ENC;
SoapObject request = new SoapObject(NAMESPACE, "login");
request.addProperty("username", "cheker");
request.addProperty("apiKey", "123456");
env.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL,3600000);
androidHttpTransport.call("", env);
Object result = env.getResponse();
Log.d("sessionId", result.toString());
SoapSerializationEnvelope env1 = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
env1.dotNet = false;
env1.xsd = SoapSerializationEnvelope.XSD;
env1.enc = SoapSerializationEnvelope.ENC;
SoapObject request1 = new SoapObject(NAMESPACE, "login");
request1.addProperty("username", "cheker");
request1.addProperty("apiKey", "123456");
env1.setOutputSoapObject(request1);
HttpTransportSE androidHttpTransport1 = new HttpTransportSE(URL,60000);
androidHttpTransport1.call("", env1);
Object result2 = env1.getResponse();
String sessionId = result.toString();
request = new SoapObject(NAMESPACE, "catalogProductList");
request.addProperty("parentCategory","2" );
request.addProperty("sessionId",sessionId );
request.addProperty("productId",1 );
env.setOutputSoapObject(request);
androidHttpTransport.call("", env);
Object result1 = env.getResponse();
ArrayList<String> ar = new ArrayList<String>();
for (int i = 0; i <((SoapObject) result1).getPropertyCount(); i++)
{
Object property = ((SoapObject) result1).getProperty(i);
if (property instanceof SoapObject)
{
SoapObject category_list = (SoapObject) property;
String mStringSchoolName = category_list.getProperty("name").toString();
// String mStringSchoolGrade = category_list.getProperty("category_id").toString();
// String mStringSchoolType = category_list.getProperty("parent_id").toString();
System.out.println("mStringSchoolName "+mStringSchoolName);
// System.out.println("mStringSchoolGrade "+mStringSchoolGrade);
// System.out.println("mStringSchoolType"+mStringSchoolType);
ar.add(mStringSchoolName+"\n\n");
}
}
for (int j = 0; j <((SoapObject) result1).getPropertyCount(); j++)
{
request = new SoapObject(NAMESPACE, "catalogProductAttributeMediaList");
request.addProperty("sessionId",sessionId );
request.addProperty("product",j+1 );
env.setOutputSoapObject(request);
androidHttpTransport.call("", env);
Object resultData1 = env.getResponse();
// System.out.println("mStringSchoolName "+resultData1);
Object property = ((SoapObject) resultData1).getProperty(0);
String url=(((SoapObject)property).getProperty("url").toString());
try {
imageURL = new URL(url);
}
catch (MalformedURLException e) {
e.printStackTrace();
}
try {
HttpURLConnection connection= (HttpURLConnection)imageURL.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream inputStream = connection.getInputStream();
bitmap = BitmapFactory.decodeStream(inputStream);//Convert to bitmap
bitmapArray.add(bitmap);
}
catch (IOException e) {
e.printStackTrace();
}
}
List<HashMap<String, Bitmap>> list= new ArrayList<HashMap<String,Bitmap>>();
for(Bitmap var: bitmapArray)
{
HashMap<String,Bitmap> map= new HashMap<String,Bitmap>();
System.out.println("Item is: " + var);
image_view.setImageBitmap(var);
map.put("key",var);
list.add(map);
}
String[] from = { "key" };
int[] to = {R.id.imageview};
SimpleAdapter adapter = new SimpleAdapter(this,list,R.layout.activity_main,from,to);
ListView listView = (ListView) findViewById(R.id.lv);
listView.setAdapter(adapter);
} catch (Exception e) {
e.printStackTrace();
}
}
}
here in output i only get last image by using **image_view.setImageBitmap(var);** in hashmap because of not adding this in listview.but i don't want this. what i want is to display images from bitmap array that contain array of bitmaps(images) in listview one by one at run time i.e load one by one using simple adapter.
so please suggest me something to acheive above mentioned requirement.I will be very thankful for your suggestions.
You Need To Use Custom Adapter to Display Images and Text in a List View... I am Posting This Link..please Check this Out...
http://www.androidinterview.com/android-custom-listview-with-image-and-text-using-arrayadapter/