0
我正在嘗試使列表視圖行爲空,如果它沒有文本。我之前已經實現了這一點,但我不確定我是如何做到的。目前,當文本沒有任何內容時,我設法讓它不顯示任何內容,但它仍然顯示行邊界。Android - 使列表視圖行不可見
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, MainActivity.values) {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView text1 = (TextView) view.findViewById(android.R.id.text1);
TextView text2 = (TextView) view.findViewById(android.R.id.text2);
text1.setText(MainActivity.values[position]);
text2.setText(MainActivity.numvalues[position]);
if (MainActivity.values[position].equals("")) {
text1.setVisibility(View.INVISIBLE);
text1.setVisibility(View.GONE);
text2.setVisibility(View.INVISIBLE);
text2.setVisibility(View.GONE);
//convertView.setVisibility(View.INVISIBLE);
//convertView.setVisibility(View.GONE);
view.setVisibility(View.INVISIBLE);
view.setVisibility(View.GONE);
}
else {
text1.setVisibility(View.VISIBLE);
text2.setVisibility(View.VISIBLE);
//convertView.setVisibility(View.INVISIBLE);
//convertView.setVisibility(View.GONE);
view.setVisibility(View.VISIBLE);
}
return view;
}
};
爲什麼你設置可見性**兩次**? 'GONE'就夠了。節省CPU週期! –