我的自定義列表視圖顯示空行,但是當我使用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;
}
}
CLASSS HERE ///////////////////// ///
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);
}
});
您是否在列表上設置適配器? – kha 2014-12-03 08:57:32
檢查:http://stackoverflow.com/questions/19079400/arrayadapter-in-android-to-create-simple-listview – 2014-12-03 09:01:03
你膨脹的觀點,但從來沒有設置任何值,所以如果XML視圖(渣油)是空的或者有空的textViews你會得到空行?! – Yazan 2014-12-03 09:06:48