gpt4 book ai didi

Android - LazyAdapter 重叠 View

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:14:20 26 4
gpt4 key购买 nike

我正在执行延迟加载以显示图像和文本。我现在已经准备好了一切,试图在 View 中添加一个 TextView 。但是,我的适配器与我的 View 重叠。更简单的说法是, ListView 与 TextView 重叠。我不确定我哪里做错了,因为 original example能够在 ListView 下方显示一个按钮,但我没有。我没有收到任何错误。我的 ListView 只覆盖了整个屏幕。知道可能是什么问题吗?

主.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();
}

}
}

适配器.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"?>
<LinearLayout
xmlns: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>

主.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">

<LinearLayout
android:id="@+id/linear1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFFFFF">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Testing 123"
/>

</LinearLayout>

<LinearLayout
android:id="@+id/linear2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/linear1"
android:background="#FFFFFF">

<ListView
android: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 重叠 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8726554/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com