相关疑难解决方法(0)

动态添加布局到android中适配器的getview方法

我想在列表视图的每一行中显示N个imageview.imageview的数量取决于json解析值.每次从服务器获取json时,它可以是2或3或4.

所以我不能通过使用inflate使用静态xml.所以我决定在getview方法中创建动态视图并在视图中添加N个imageview

我写下面的代码,但它仍然只显示一个imageview和水平滚动根本不工作..

任何帮助表示赞赏

public class MyAdapter extends BaseAdapter{
private LayoutInflater inflater;
private ArrayList<String> data;
Context con;

public MyAdapter(Context context, ArrayList<String> data1){
// Caches the LayoutInflater for quicker use
      inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// Sets the events data
data= data1;
con=context;
}

public View getView(int position, View view, ViewGroup viewgroup) {
    ViewHolder holder=new ViewHolder(); //our view holder of the row
    if (view == null) {

        HorizontalScrollView hr=new HorizontalScrollView(con);
        LinearLayout layout=new LinearLayout(con);
        layout.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));

           //layout set some properties
           for(int i=1;i<2;i++)
           {
            holder.image …
Run Code Online (Sandbox Code Playgroud)

android android-arrayadapter imageview

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

android-arrayadapter ×1

imageview ×1