0

私は with を使用actionBarSherlockしてSherlockListFragmentおり、カスタムを設定したいと考えていますBaseAdpater。アダプターAsyncTaskを解析して入力するために使用しています。JSONしかし、listview表示されていません。フラグメントは空です。これは私が試しているコードです:

public class LatestSubmissions extends SherlockListFragment {

    LatestSubmissionsAdapter adapter = null;

    ArrayList<HashMap<String, String>> submissions = new ArrayList<HashMap<String, String>>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        new GetSubmissionsListTask().execute(CommonUtils.USER_SUBMISSION_URL);
        return super.onCreateView(inflater, container, savedInstanceState);
    }

    protected class GetSubmissionsListTask extends
            AsyncTask<String, Void, String> {

        @Override
        protected String doInBackground(String... params) {
            return new JSONFetcher().getJSONStringFromUrl(params[0]);
        }

        @Override
        protected void onPostExecute(String result) {
            try {
                JSONObject jObject = new JSONObject(result);
                //related code
                submissions.add(map);
                }
            } catch (JSONException e) {

            }
            adapter = new LatestSubmissionsAdapter(getSherlockActivity(), submissions);
            setListAdapter(adapter);
        }
    }
}

これが LatestSubmissionsAdapter です。

public class LatestSubmissionsAdapter extends BaseAdapter {
    private Context mContex;
    private ArrayList<HashMap<String, String>> data;
    private static LayoutInflater inflater = null;

    public LatestSubmissionsAdapter(Context context,
            ArrayList<HashMap<String, String>> data) {
        this.mContex = context;
        this.data = data;
        inflater = (LayoutInflater) mContex
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        if (convertView == null)
            vi = inflater.inflate(R.layout.latest_submissions, null);
        RelativeLayout firstRow = (RelativeLayout) vi
                .findViewById(R.id.first_row);
        TextView language = (TextView) firstRow.findViewById(R.id.lang);
        TextView verdict = (TextView) firstRow.findViewById(R.id.verdict);
        RelativeLayout secondRow = (RelativeLayout) vi
                .findViewById(R.id.second_row);
        TextView problem = (TextView) secondRow
                .findViewById(R.id.problem_name_id);
        TextView rank = (TextView) secondRow.findViewById(R.id.rank);
        RelativeLayout thirdRow = (RelativeLayout) vi
                .findViewById(R.id.third_row);
        TextView submissionTime = (TextView) thirdRow
                .findViewById(R.id.submit_time);
        TextView executionTime = (TextView) thirdRow
                .findViewById(R.id.exec_time);

        HashMap<String, String> submissionInfo = new HashMap<String, String>();
        submissionInfo = data.get(position);

        language.setText(submissionInfo.get(CommonUtils.KEY_LANGUAGE_ID));
        verdict.setText(submissionInfo.get(CommonUtils.KEY_VERDICT_ID));

        problem.setText(submissionInfo.get(CommonUtils.KEY_PROBLEM_ID));
        rank.setText(submissionInfo.get(CommonUtils.KEY_SUBMISSION_RANK));

        submissionTime.setText(submissionInfo
                .get(CommonUtils.KEY_SUBMISSION_TIME));
        executionTime.setText(submissionInfo.get(CommonUtils.KEY_RUNTIME));

        return vi;
    }

}

JSON は適切に所有され、解析されます。しかし、問題はリストビューです。

4

1 に答える 1

1

あなたはあなたをオーバーライドする必要があります

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return null;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

ListView は項目が 0 であると見なすため、何も表示されません。

于 2013-07-28T18:00:12.973 に答える