gpt4 book ai didi

java - 如何 TextView.setText(Listobject) 像 TextView.setText(array[index]) settext from List

转载 作者:太空狗 更新时间:2023-10-29 15:32:29 27 4
gpt4 key购买 nike

你好,我有一个列表,我试着做 settext从它,例如我知道TextView.setText(List<String>object)喜欢TextView.setText(array[index])但它不起作用。我也尝试使用 get。这是实现自定义适配器的正确方法吗:首先我应该设置文本列表,然后我将添加图像等等。下面是我的代码:

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);

}
}

适配器类:

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;
}
}

最佳答案

用这个

TextView.setText(String.valueOf(array[index]));

关于java - 如何 TextView.setText(List<String>object) 像 TextView.setText(array[index]) settext from List,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28122539/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com