我这里有这个代码:
CustomAdapter adapter = new CustomAdapter(myActivity.this, R.layout.listitemrow,
catalogList);
myListView.setAdapter(adapter);
....
class CustomAdapter:
public class CustomAdapter extends ArrayAdapter<String>{
public CustomAdapter(Activity a, int textViewResourceId, ArrayList<String> tweets){
....
}
....
}
listitemrow是android布局文件夹中的xml。
出于某种原因,我不想使用R.layout.listitemrow
。我想使用在代码中创建的mylayout:
public class myLayout extends RelativeLayout{
.....
}
有没有这样做?像这样:
CustomAdapter adapter = new CustomAdapter(myActivity.this, new myLayout() ,
catalogList);
谢谢。
答案 0 :(得分:0)
您应该覆盖适配器的getView()
方法:
public class CustomAdapter extends ArrayAdapter{
public CustomAdapter(Activity a, int textViewResourceId, ArrayList<String> tweets){
....
}
public View getView(int position, View convertView, ViewGroup parent) {
View itemview = new myLayout(parent.getContext());
...
return itemView;
}
....
}