0

我在这里有这段代码:

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

谢谢你。

4

1 回答 1

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

   ....
}
于 2012-08-02T11:54:59.547 回答