我想使列表视图中的某些项目没有显示在列表视图中,并且我从json获取数据。我不知道我应该写什么代码来使listview中的某些项目不显示在列表中,或者它的最佳做法是什么。
这是我的代码
String nama = ar.getString("nama");
String status = ar.getString("status");
String keterangan = ar.getString("keterangan");
String tanggal = ar.getString("updated_at");
idaset = ar.getInt("id");
foto = ar.getString("foto");
if (ar.has("asset_parent") && !ar.isNull("asset_parent")) {
JSONObject parent = ar.getJSONObject("asset_parent");
nama2 = parent.getString("nama");
if (parent.has("asset_parent") && !parent.isNull("asset_parent")) {
JSONObject parent2 = parent.getJSONObject("asset_parent");
nama3 = parent2.getString("nama");
}
}
if (status == "1") {
//code for not showing the row in listview
} else {
if (tanggal.equals("null"))
reports.add(new Word(nama, nama3, nama2, "", foto, keterangan, idaset));
else
reports.add(new Word(nama, nama3, nama2, tanggal, foto, keterangan, idaset));
}
}
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
LinearLayout rootView = (LinearLayout) findViewById(R.id.root_view1);
adapter = new WordAdapter(UpdateActivity.this, reports, R.color.putih);
final ListView listView = (ListView) findViewById(R.id.list1);
listView.setAdapter(adapter);
这是我制作列表的pojo
public WordAdapter(Context context, ArrayList<Word> words, int colorResourceId) {
super(context, 0, words);
mColorResourceId = colorResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
View listItemView = convertView;
if (listItemView == null) {
listItemView = LayoutInflater.from(getContext()).inflate(
R.layout.isi_listview, parent, false);
}
Word currentWord = getItem(position);
TextView asetTextView = (TextView) listItemView.findViewById(R.id.text1);
asetTextView.setText(currentWord.getAset());
TextView ruangTextView = (TextView) listItemView.findViewById(R.id.text4);
ruangTextView.setText(currentWord.getRuang());
TextView tanggalTextView = (TextView) listItemView.findViewById(R.id.text3);
tanggalTextView.setText(currentWord.getTanggal());
View textContainer = listItemView.findViewById(R.id.text_container);
int color = ContextCompat.getColor(getContext(),mColorResourceId);
textContainer.setBackgroundColor(color);
return listItemView;
}
请帮助如何做得好