请朋友们帮帮我。这个程序有什么问题。我不能在这里使用 LayoutInflater。如何解决这个问题呢。
public class MyListAdapter extends ArrayAdapter<MyData> implements
OnClickListener {
private ArrayList<MyData> items;
Context context;
public MyListAdapter(Context context, int textViewResourceId,
ArrayList<MyData> items) {
super(context, textViewResourceId, items);
this.items = items;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
}
MyData myData = items.get(position);
if (myData != null) {
TextView textViewTwo = (TextView) v
.findViewById(R.id.text_view_two);
if (textViewTwo != null) {
textViewTwo.setText(myData.getText());
// put the id to identify the item clicked
textViewTwo.setTag(myData.getId());
textViewTwo.setOnClickListener(this);
}
}
return v;
}
public void onClick(View v) {
// TODO Auto-generated method stub
Log.d("Sample", "Clicked on tag: " + v.getTag());
Toast.makeText(context, "", Toast.LENGTH_SHORT).show();
}
}
错误是:未为 MyListAdapter 类型定义方法 getSystemService(String)。
提前致谢。