如何从List中TextView.setText(List <String>对象)像TextView.setText(array [index])settext

Jes*_*sie 2 java android

你好,我有一个名单,我试着做settext从它,比如我知道, TextView.setText(List<String>object)喜欢TextView.setText(array[index]) ,但它不是working.I试图用GET also.Is它来实现自定义的适配器的正确方法:firtsly我的setText列表,然后我会加图像等.以下是我的代码:

public class GetName  extends Fragment {
ListView listview;
List<ParseObject> ob;
ProgressDialog mProgressDialog;
//ArrayAdapter<String> adapter;
 CustomList adapter;

public GetName()
{

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    Parse.initialize(getActivity(), "user", "pass");    
    defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);
    View view=inflater.inflate(R.layout.getnewlay,container, false);


    new GetData().execute();
    return view;
}

private class GetData extends AsyncTask<Void, Void, Void> {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        mProgressDialog = new ProgressDialog(getActivity());
        mProgressDialog.setTitle("Parse.com Simple ListView Tutorial");
        mProgressDialog.setMessage("Loading...");
        mProgressDialog.setIndeterminate(false);
        mProgressDialog.show();
    }

    @Override
    protected Void doInBackground(Void... params) {

        ParseQuery query = new ParseQuery("Name");
        query.orderByDescending("_created_at");
        try {
            ob = query.find();


        } catch (ParseException e) {
            Log.e("Error", e.getMessage());
            e.printStackTrace();
        }
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {

        listview = (ListView)getView().findViewById(R.id.listviewget);

        adapter = new CustomList(getActivity(), ob);
                /*ArrayAdapter<String>(getActivity(),
                R.layout.listview_item);*/
        // Retrieve object "name" from Parse.com database
        for (ParseObject country : ob) {
            adapter.add((String) country.get("name"));
        }
        listview.setAdapter(adapter);

    }
}
Run Code Online (Sandbox Code Playgroud)

}

适配器类:

public class CustomList extends ArrayAdapter<String> {

private final Activity context;
private final String[] descr;
private final Integer[] imageId;
private final Integer[] imagId;*/
private List<ParseObject> ob;

public CustomList(Activity context, List<ParseObject> ob) {
    super(context, R.layout.list_single);
    this.ob = ob;
    this.context = context;

}

@Override
public View getView(int position, View view, ViewGroup parent) {
    LayoutInflater inflater = context.getLayoutInflater();
    View rowView = inflater.inflate(R.layout.list_single, null, true);
    TextView txtTitle = (TextView) rowView.findViewById(R.id.lname);

    >for(ParseObject i : ob) txtTitle.setText((CharSequence) i);
    >   txtTitle.setText( ob.get(position));

    return rowView;
}
}
Run Code Online (Sandbox Code Playgroud)

Nar*_*had 5

用这个

TextView.setText(String.valueOf(array[index]));
Run Code Online (Sandbox Code Playgroud)