开发者

Setting Json Array in listview but while clicking on particular list item, listview get hang

I am parsing below jsong String and able to parse also and set in listview but while clicking on particular list item it get hang and doesn't fire any error or doesn't perform any action. What will be the possible solution for that?

thanks.

Json String

try {
            output= httpObject.OpenHttpConnection(HomesUrl);
        } catch (ProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        try {
            parseJsonResponse(output);
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



        mEditorialList.setOnItemClickListener( new OnItemClickListener() {
                public void onItemClick(AdapterView<?> arg0, View v,
                    int position, long id) {
                    System.out.println("clicked");
                //Intent mEditorialIntent = new Intent(Homes.this, BrowseDetailsPage.class);
                //startActivity(mEditorialIntent);
                    System.out.println("clicked");
            }
        });

parserClass:

public void parseJsonResponse(String output) throws JSONException {
        // TODO Auto-generated method stub

    if(output!=null){   
        try {

            mFeaturedArraylist = new JSONArray();
            mFeaturedArraylist=new JSONObject(output).getJSONObject("Data").getJSONArray("Featured");

            for (int i = 0; i < mFeaturedArraylist.length(); i++) {
                JSONObject headObject = mFeaturedArraylist.getJSONObject(i);
                mTextViewHead.setText(headObject.optString("Title"));
            }

            mEditorialArraylist = new JSONArray();
            mEditorialArraylist = new JSONObject(output).getJSONObject("Data").getJSONArray("Editorials");

            globalAdapter = new EditorialAdapter(Homes.this, mEditorialArraylist);
                mEditorialList.setAdapter(globalAdapter);

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }
}

EditorialAdapter:

public class EditorialAdapter extends BaseAdapter{
private LayoutInflater mInflater;
JSONArray mEditorial;



public EditorialAdapter(Context context, JSONArray arrList){
    mEditorial = arrList;
    mInflater = LayoutInflater.from(context);

}


public int getCount() {
    // TODO Auto-generated method stub
    return mEditorial.length();
}

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}
 public class ViewHolder{
    TextView twtdata;
    ImageView twtimg;
    TextView twtnm;
}

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    ViewHolder holder;
    View vi= convertView;

    if(convertView==null){

        vi= mInflater.inflate(R.layout.home_listrow, null);

        holder = new ViewHolder();

        holder.twtdata = (TextView) vi.findViewById(R.id.txtlistby);
        holder.twtnm = (TextView) vi.findViewById(R.id.txtlisttitle);
        holder.twtimg = (ImageView) vi.findViewById(R.id.avatar);
        vi.setTag(holder);


    }
    else{
        holder = (ViewHolder) vi.getTag();
        }
        try {
            JSONObject jObj = mEditorial.optJSONObject(position);
            holder.twtnm.setText(jObj.getString("Title"));
            holder.twtdata.setText("By "+jObj.getString("AuthorName"));

        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    return v开发者_如何转开发i;
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜