public class AdapterListView extends BaseAdapter {
Context context;
ArrayList<String> brands;
public AdapterListView(ArrayList<String> brands, Context context) {
this.brands = brands;
this.context = context;
}
@Override
public int getCount() {
return brands.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
view= LayoutInflater.from(context).inflate(R.layout.activity_listview,null);
ListView lv=(ListView)view.findViewById(R.id.mobile_list);
lv.setText(brands.get(i));
return view;
}
}
setText有错误并显示(无法解析方法,settext(java.lag.string))
我的消息片段类是在实际上尝试设置listview
时给出的 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_messages, container, false);
brands.add("microsoft");
brands.add("ios" );
brands.add("android");
AdapterListView adapter = new AdapterListView(brands,getActivity());
ListView listView = (ListView)rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
// Inflate the layout for this fragment
return rootView;
}
我需要打印列表brands.is在我设置listview的方式中出现任何错误
答案 0 :(得分:1)
setText有错误并显示(无法解析 方法,的setText(java.lag.string))
因为setText
类中未定义ListView
方法。
使用TextView,EditText,类似按钮的视图来使用setText
方法
答案 1 :(得分:0)
而不是
ListView lv=(ListView)view.findViewById(R.id.mobile_list);
lv.setText(brands.get(i));
您必须在TextView
中R.layout.activity_listview
而且代码应该是
TextView tv=(TextView)view.findViewById(R.id.textViewId);
tv.setText(brands.get(i));