Android – LazyAdapter重叠视图

Android – LazyAdapter重叠视图,第1张

概述我正在进行延迟加载以显示图像和文本.我现在已经掌握了一切,尝试在视图中添加textview.但是,我的适配器与我的视图重叠.更简单的术语是,listview与textview重叠.我不确定我在哪里做错了因为 original example能够在列表视图下面显示一个按钮,但我不是.我没有收到任何错误.我的列表视图只涵盖了整个屏幕.知道可能是什么问题吗? main.java public class 我正在进行延迟加载以显示图像和文本.我现在已经掌握了一切,尝试在视图中添加textvIEw.但是,我的适配器与我的视图重叠.更简单的术语是,ListvIEw与textvIEw重叠.我不确定我在哪里做错了因为 original example能够在列表视图下面显示一个按钮,但我不是.我没有收到任何错误.我的列表视图只涵盖了整个屏幕.知道可能是什么问题吗?

main.java

public class main extends Activity {private static final String targetURL ="http://www.Google.com/images";ListVIEw List;ProgressDialog dialog;private String[] mStrings = {};private String[] dStrings = {};//TextVIEw tv;public voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.main);             new TheTask().execute();    List=(ListVIEw)findVIEwByID(R.ID.List);    TextVIEw tv = (TextVIEw)findVIEwByID(R.ID.tv);    //tv.setText("Text VIEw is displayed");}   protected class TheTask extends AsyncTask<VoID,VoID,MyResultClass >{    protected voID onPreExecute() {        dialog = ProgressDialog.show(Cats.this,"RetrIEving information","Please wait for few seconds...",true,false);        dialog.setCancelable(true);    }    protected MyResultClass doInBackground(VoID... params) {        searchContent();        MyResultClass result = new MyResultClass();        result.mStrings = mStrings;        result.dStrings = dStrings;        return result;    }       protected voID onPostExecute(MyResultClass result) {                    dStrings = result.dStrings;        mStrings = result.mStrings;                 LazyAdapter adapter = new LazyAdapter(Cats.this,mStrings,dStrings);        List.setAdapter(adapter);        dialog.dismiss();    }       }    class MyResultClass    {         public String[] mStrings;         public String[] dStrings;     }public voID searchContent(){    String imageC = "";    String textC = "";    try {        URL url = new URL(targetURL);        // Make the connection        URLConnection conn = url.openConnection();        BufferedReader reader = new BufferedReader(         new inputStreamReader(conn.getinputStream()));        String line = reader.readline();        Pattern sChar = Pattern.compile("&.*?;");        line.replaceAll("\<.*?\>","");        Matcher msChar = sChar.matcher(line);        while (msChar.find()) line = msChar.replaceAll("");        while (line != null) {            if(line.contains("../../"))            {                int startIndex = line.indexOf("../../") + 6;                int endindex = line.indexOf(">",startIndex + 1);                String abc = "http://www.Google.com/";                String imageSrc = line.substring(startIndex,endindex);                //complete full url                String xyz = abc +imageSrc;                xyz = xyz.substring(0,xyz.indexOf('"'));                xyz = xyz +";";                xyz = xyz.replaceAll(" ","%20");                imageC += xyz;                                  mStrings = imageC.split(";");                line = reader.readline();            }            if(line.contains("../../") == false)            {                line = reader.readline();            }            if (line.contains("GnaMetag"))            {                int startIndex = line.indexOf("GnaMetag") + 10;                int endindex = line.indexOf("<",startIndex + 1);                String gname = line.substring(startIndex,endindex);                textC = textC.replaceAll("</span>","");                textC += "name: "+gname+ "\n";            }                if (line.contains("Age"))                {                    textC += "Age: "+reader.readline() + "\n" + ";";                    textC = textC.replaceAll("                  ","");                    dStrings = textC.split(";");                }            if (line.contains("Last Update"))            {                reader.close();            }                                       }                   // Close the reader        reader.close();    } catch (Exception ex) {        ex.printstacktrace();               }     }}

Adapter.java

public VIEw getVIEw(int position,VIEw convertVIEw,VIEwGroup parent) {    VIEw vi=convertVIEw;    VIEwHolder holder;    if(convertVIEw==null){        vi = inflater.inflate(R.layout.item,null);        holder=new VIEwHolder();        holder.text=(TextVIEw)vi.findVIEwByID(R.ID.text);;        holder.image=(ImageVIEw)vi.findVIEwByID(R.ID.image);        vi.setTag(holder);    }    else        holder=(VIEwHolder)vi.getTag();    holder.text.setText(text[position]);    holder.image.setTag(data[position]);    imageLoader.displayImage(data[position],activity,holder.image);    return vi;}

item.xml(由Adapter.java使用)

<?xml version="1.0" enCoding="utf-8"?><linearLayoutxmlns:androID="http://schemas.androID.com/apk/res/androID"androID:layout_wIDth="fill_parent"androID:layout_height="wrap_content"androID:background="#FFFFFF"><ImageVIEw  androID:ID="@+ID/image"  androID:layout_wIDth="90dip"  androID:layout_height="90dip"   androID:src="@drawable/stub"   androID:scaleType="centerCrop"  androID:layout_gravity="left|center_vertical"   /><TextVIEw  androID:ID="@+ID/text"  androID:layout_wIDth="fill_parent"  androID:layout_height="wrap_content"  androID:gravity="center"  androID:textSize="15dip"/></linearLayout>

main.xml中

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"androID:orIEntation="vertical"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:background="#FFFFFF"><linearLayoutandroID:ID="@+ID/linear1"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:background="#FFFFFF"><TextVIEwandroID:ID="@+ID/tv"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"androID:text="Testing 123"/> </linearLayout><linearLayoutandroID:ID="@+ID/linear2"androID:layout_wIDth="wrap_content"androID:layout_height="wrap_content"    androID:layout_below="@+ID/linear1"androID:background="#FFFFFF"><ListVIEwandroID:ID="@+ID/List"androID:layout_wIDth="fill_parent"androID:layout_height="wrap_content"androID:layout_marginBottom="30dp"/></linearLayout></relativeLayout>
解决方法 只需从此行中删除符号即可

androID:layout_below="@+ID/linear1"

在第二个线性布局节.

总结

以上是内存溢出为你收集整理的Android – LazyAdapter重叠视图全部内容,希望文章能够帮你解决Android – LazyAdapter重叠视图所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1128493.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存