gpt4 book ai didi

android - 显示空行的自定义 ListView

转载 作者:行者123 更新时间:2023-11-29 20:57:11 24 4
gpt4 key购买 nike

我的自定义 ListView 显示空行,但是当我使用 logcat 显示数据时,它显示数据都在我的数组列表中...如何让 ListView 显示我的数组列表项?

public class Myarrayadapter extends ArrayAdapter<String> {

Context context;
ArrayList<String> values;
int resid;

public Myarrayadapter(Context context, int resid, ArrayList<String> values) {
super(context, resid, values);
this.resid = resid;
this.context = context;
this.values = values;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(resid, parent, false);
return rowView;
}
}

在这里上课////////////////////////////////////////

    final ListView HomeListView = (ListView) findViewById(R.id.HomeListView);
String[] filelist = fileList();
ArrayList<String> fileList = new ArrayList<String>();

for (int i=0; i < filelist.length; i++) {//displays only first half of job number
String[] stemp = filelist[i].split("\\.");
if(!fileList.contains(stemp[0])) {//makes sure only one job number is show in the list
fileList.add(stemp[0]);
}
}
Collections.reverse(fileList);
Myarrayadapter listAdapter = new Myarrayadapter(this, R.layout.homelistview, fileList);
HomeListView.setAdapter(listAdapter);
HomeListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//get the clicked items job no. and pass it to the next activity which will display all relevant jobs
Intent detailedlist_intent = new Intent(Home.this, Home2.class);
detailedlist_intent.putExtra("Jobno", HomeListView.getItemAtPosition(position).toString());
startActivity(detailedlist_intent);
}
});

最佳答案

您应该将值设置为 resid 布局内的 textview。您没有将文本设置为 TextView 。这就是为什么它空空如也。

关于android - 显示空行的自定义 ListView ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27267205/

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