Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/208.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 具有文本视图、图像、复选框和按钮的Listview_Android_Xml - Fatal编程技术网

Android 具有文本视图、图像、复选框和按钮的Listview

Android 具有文本视图、图像、复选框和按钮的Listview,android,xml,Android,Xml,我似乎在为listview创建适配器以显示另一个.xml类中的项目(标题上的内容)时遇到问题 有人能给我一个例子或提示我应该使用哪个适配器吗 使用?在ListView上添加项目xml项目 无论如何,我不会生成任何新项目。我只使用另一个xml中的每个现有项 下面是我希望将另一个xml转换为listview的图像 之所以这样做是因为将来我想在新列表中添加项目。您需要使用CustomAdapter扩展BaseAdapter,如下代码和链接所示 主要思想是为listview的单个项创建XML布局 然

我似乎在为listview创建适配器以显示另一个.xml类中的项目(标题上的内容)时遇到问题

有人能给我一个例子或提示我应该使用哪个适配器吗 使用?在ListView上添加项目xml项目

无论如何,我不会生成任何新项目。我只使用另一个xml中的每个现有项

下面是我希望将另一个xml转换为listview的图像


之所以这样做是因为将来我想在新列表中添加项目。

您需要使用CustomAdapter扩展BaseAdapter,如下代码和链接所示


主要思想是为listview的单个项创建XML布局


然后创建一个CustomAdapter以附加到ListView。使用getView()可以初始化其中的单行数据/事件。您可以在那里找到各种实现相同功能的示例。

现在,所有的硬答案都没有一致性

这里有一个更简单的解决方案,或者说是一个简单的解决方案,以及实际操作的过程

  • 使用GUI设置开始构建线性布局,确保它们正确对齐。我的方向是垂直的

  • 完成后,将所有内容从上到下复制并粘贴到记事本上,然后移除

  • 现在在相对布局上创建。宽度和高度=匹配父项。方向垂直

  • 现在添加一个Scrollview,其中包含高度和宽度的wrap_内容。然后将第2项任务中的所有内容粘贴起来


  • 这就是整个视图的整个滚动视图。

    与我的主要区别在于将其转换为listview,正如我所说,我在另一个xml文件中有一些项目,我想将其放在listview中。我不想用新信息来填充它,而只是先存在的xml。大多数其他示例演示了如何填充它们,而不是从一个xml中获取它们并仅显示它们。xml只是一个空视图。。您可以获取它的视图/设计/用户界面(通过Java代码,通过从现有的xml布局中膨胀),它的数据:在getView()中,您必须提供某种方式将数据放入其中……确实,但膨胀后需要填充。在填充通用项的过程中,从另一个.xml文件调用这些项以将其转换为listview会有困难。我张贴了一张图片,这样我可以向您展示我想要转换成listview的内容。而且大多数示例都使用数组填充。没有。当我查看holder时,它意味着我正在用一行中的两个通用项填充一个列表。我想要的更像是xml数据到listview之间的传输。我将展示一幅图片,以便更好地理解我正在尝试做的事情。
    public class List14 extends ListActivity {
    
        private static class EfficientAdapter extends BaseAdapter {
            private LayoutInflater mInflater;
            private Bitmap mIcon1;
            private Bitmap mIcon2;
    
            public EfficientAdapter(Context context) {
                // Cache the LayoutInflate to avoid asking for a new one each time.
                mInflater = LayoutInflater.from(context);
    
                // Icons bound to the rows.
                mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1);
                mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2);
            }
    
            /**
             * The number of items in the list is determined by the number of speeches
             * in our array.
             *
             * @see android.widget.ListAdapter#getCount()
             */
            public int getCount() {
                return DATA.length;
            }
    
            /**
             * Since the data comes from an array, just returning the index is
             * sufficent to get at the data. If we were using a more complex data
             * structure, we would return whatever object represents one row in the
             * list.
             *
             * @see android.widget.ListAdapter#getItem(int)
             */
            public Object getItem(int position) {
                return position;
            }
    
            /**
             * Use the array index as a unique id.
             *
             * @see android.widget.ListAdapter#getItemId(int)
             */
            public long getItemId(int position) {
                return position;
            }
    
            /**
             * Make a view to hold each row.
             *
             * @see android.widget.ListAdapter#getView(int, android.view.View,
             *      android.view.ViewGroup)
             */
            public View getView(int position, View convertView, ViewGroup parent) {
                // A ViewHolder keeps references to children views to avoid unneccessary calls
                // to findViewById() on each row.
                ViewHolder holder;
    
                // When convertView is not null, we can reuse it directly, there is no need
                // to reinflate it. We only inflate a new View when the convertView supplied
                // by ListView is null.
                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.list_item_icon_text, null);
    
                    // Creates a ViewHolder and store references to the two children views
                    // we want to bind data to.
                    holder = new ViewHolder();
                    holder.text = (TextView) convertView.findViewById(R.id.text);
                    holder.icon = (ImageView) convertView.findViewById(R.id.icon);
    
                    convertView.setTag(holder);
                } else {
                    // Get the ViewHolder back to get fast access to the TextView
                    // and the ImageView.
                    holder = (ViewHolder) convertView.getTag();
                }
    
                // Bind the data efficiently with the holder.
                holder.text.setText(DATA[position]);
                holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);
    
                return convertView;
            }
    
            static class ViewHolder {
                TextView text;
                ImageView icon;
            }
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setListAdapter(new EfficientAdapter(this));
        }
    
        private static final String[] DATA = Cheeses.sCheeseStrings;
    }