在我的代码中按时间在Android中制作可排序的ListView

时间:2015-08-19 20:09:20

标签: android sorting listview adapter

  • 我尝试了很多方法,但我不想按时间排序......
  • 我想在最新的
  • 中展示旧项目
  • 谢谢我不知道如何使用或使用什么方法,以及我应该在哪里复制适配器类的详细信息

以下是源代码:

public class AdapterImage extends ArrayAdapter<StructureImage> {

    public AdapterImage(ArrayList<StructureImage> array) {
        super(G.context, R.layout.adapter_images, array);
    }

    private static class ViewHolder {

        public ViewGroup layoutRoot;
        public TextView  txtTitle;
        public TextView  txtTozih;
        public ImageView imgPreview;


        public ViewHolder(View view) {
            layoutRoot = (ViewGroup) view.findViewById(R.id.layoutRoot);
            txtTitle = (TextView) view.findViewById(R.id.txtTitle);
            txtTozih = (TextView) view.findViewById(R.id.txtTozih);
            imgPreview = (ImageView) view.findViewById(R.id.imgPreview);
        }


        public void fill(final ArrayAdapter<StructureImage> adapter, final StructureImage item, final int position) {
            txtTitle.setText(item.title);
            txtTozih.setText(item.tozihat);
            imgPreview.setClickable(true);
            imgPreview.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    Toast.makeText(G.context, txtTitle.getText() + "", Toast.LENGTH_SHORT).show();
                }
            });
            String filename = item.thumbnail.replace("/thumbnail/", "");
            final File imageFile = new File(G.DIR_FINAL + "/" + filename);
            if ( !imageFile.exists()) {
                imgPreview.setImageBitmap(null);
                DownloadManager.addToDownloadList(item.thumbnail);
            }

            BitmapFactory.Options options = new BitmapFactory.Options();
            //options.inSampleSize = 8;
            Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath(), options);
            imgPreview.setImageBitmap(bitmap);



        }
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        StructureImage item = getItem(position);
        if (convertView == null) {
            convertView = G.inflater.inflate(R.layout.adapter_images, parent, false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        holder.fill(this, item, position);
        return convertView;
    }
}

1 个答案:

答案 0 :(得分:0)

让我抓住这个,因为它似乎有足够的兴趣。完成显示最早的第一个方法的一种方法是在构造函数中对列表进行排序:

<form action="second.html" method="GET" >
    <!-- In this way we can get submitted data from get param "host" -->
    <input type="text" name="host" /> 
    <input type="submit" value="Submit" />
</form>