gpt4 book ai didi

java - ListActivity 中只出现一行

转载 作者:行者123 更新时间:2023-12-02 08:07:46 27 4
gpt4 key购买 nike

我正在尝试创建一个 ListActivity,其行包含文本和图像。但它只显示一行的值,其他行的图像和文本是不可见的。当我调试代码时,它们的值不为空。但它显示行,但除了第一行之外,在布局上不显示这些文本和图像值。这是我的代码:

public class SutList extends ListActivity implements XmlListener,OnItemClickListener{
XMLParser xmlParser;
@SuppressWarnings("rawtypes")
ArrayList sutList = new ArrayList();
ProgressDialog sutProgress;
XmlObjectAdapter xmlObj;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

xmlParser = new XMLParser("http://192.168.2.101/eczaplus/AndroidAPI/search.php?searchtype=drug_sut&keyword="+SharedItems.getInstance().clickedObject.map.get("id"));
xmlParser.addMyEventListener(this);
xmlParser.startAsyncTask();

getListView().setOnItemClickListener(this);
}

@Override
public void xmlParsed(XmlEvent evt) {
sutList = evt.ownerClient.children;
xmlObj = new XmlObjectAdapter(this, R.layout.esdegerilac, sutList);
setListAdapter(xmlObj);
}

@Override
public void preExecute(EventObject evt) {
sutProgress = new ProgressDialog(SutList.this);
sutProgress.setProgressStyle(ProgressDialog.STYLE_SPINNER);
sutProgress = ProgressDialog.show(SutList.this,"", "");

}

@Override
public void postExecute(EventObject evt) {
sutProgress.dismiss();

}

private class XmlObjectAdapter extends ArrayAdapter<XmlObject> {

private ArrayList<XmlObject> items;

public XmlObjectAdapter(Context context, int textViewResourceId, ArrayList<XmlObject> items) {
super(context, textViewResourceId, items);
this.items = items;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.sutlist, null);
}
XmlObject o = items.get(position);
// System.out.println(o.map.get("name"));
if (o != null) {
TextView ilacText = (TextView) findViewById(R.id.sutNameText);
ImageView sutImage = (ImageView) findViewById(R.id.sutImage);
//HashMap< String, String> atr = (HashMap<String, String>) o.map;
if (sutImage != null){
if (o.map.get("exists").equals("1"))
sutImage.setImageResource(R.drawable.ok);
else
sutImage.setImageResource(R.drawable.not_ok);

if (ilacText != null)
ilacText.setText(o.map.get("title"));

}

}
return v;
}
}

希望您能帮我解决这个问题。

最佳答案

在 getView() 中的 XmlObjectAdapter 中,我相信你想要

 v.findViewById() 

不只是

 findViewById()

关于java - ListActivity 中只出现一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7891480/

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