dimanche 19 avril 2015

GetView method is not getting called in android list view

I am new to android.I want to work with list view that contain both image and text.getView method is not getting called while I am trying to debug.I need a solution for this.I am trying to bind the item data to list view.Here is my code



public class ResultActivity extends ActionBarActivity {
public List<String> itemList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
JSONObject obj = null;
try {
obj = new JSONObject(getIntent().getStringExtra("json"));
} catch (JSONException e) {
e.printStackTrace();
}
try {
parseJsonData(obj);
} catch (JSONException e1) {
e1.printStackTrace();
}
}
public void parseJsonData(JSONObject obj) throws JSONException {


try {

int j=0;
String ack = (String) obj.get("ack");
int itemCount =obj.getInt("itemCount");
String ItemPrice="";

for(j=0;j<itemCount;j++) {
itemList = new ArrayList<String>();
String itemObject = "item"+1;

JSONObject itemObj = obj.getJSONObject(itemObject);

JSONObject BasicInfoObj =itemObj.getJSONObject("basicInfo");
JSONObject sellerInfoObj =itemObj.getJSONObject("sellerInfo");
JSONObject shippingInfoObj = itemObj.getJSONObject("shippingInfo");
String galleryURL = BasicInfoObj.getString("galleryURL");
String pictureURLSuperSize =BasicInfoObj.getString("pictureURLSuperSize");
int CurrentPrice=BasicInfoObj.getInt("convertedCurrentPrice");
int shippingServiceCost =BasicInfoObj.getInt("shippingServiceCost");
String title =BasicInfoObj.getString("title");

if(CurrentPrice == 0)
{
ItemPrice ="Price:"+" "+"$"+shippingServiceCost+" "+"(FREE Shipping)";
}
else
{
ItemPrice = "Price:"+" "+"$"+shippingServiceCost+" "+ "(+$"+ CurrentPrice+ "for Shipping)";
}
itemList.add(0,galleryURL);
itemList.add(1,pictureURLSuperSize);
itemList.add(2,title);
itemList.add(3,ItemPrice);
populateListView();

}
}


catch (JSONException e) {
e.printStackTrace();
}
}

private void populateListView()
{
ArrayAdapter<String> adapter =new MyListAdapter();
ListView list =(ListView) findViewById(R.id.ItemListView);
list.setAdapter(adapter);
adapter.getCount();


}
private class MyListAdapter extends ArrayAdapter<String> {
public MyListAdapter()
{
super(ResultActivity.this,R.layout.item_view,itemList);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if(itemView==null) {
itemView =getLayoutInflater().inflate(R.layout.item_view,parent,false);
}
String itemtowork =itemList.get(position);
ImageView imageView =(ImageView)itemView.findViewById(R.id.item_icon);
//String ImageUrl=itemtowork.;
//imageView.setImageURI();

return itemView;
}


}




@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);

}


}

Aucun commentaire:

Enregistrer un commentaire