我使用适配器来设置项目布局并ListView
从 JSON 字符串填充 a。有时这个 JSON 是空的,并且没有任何行进入ListView
并且它是完全空白的。
在这种情况下,我想更改视图并传递另一个显示“这里没有任何行”的布局。
所以这是我的代码:
MainActivity.java
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView listView = (ListView) findViewById(R.id.listView);
List list = new LinkedList();
[...fill list...]
ListAdapter adapter = new ListAdapter(this, R.layout.list_row_layout, list, R.id.edCod, R.id.edDes);
listView.setAdapter(adapter);
}
}
ListAdapter.java
public class ListAdapter extends ArrayAdapter<Adapter> {
private LayoutInflater layoutInflater;
private int layout;
private int textCod;
private int textDes;
public FruttaAdapter(Context context, int layout, List<Adapter> objects, int textCod, int textDes) {
super(context, layout, objects);
this.layout = layout;
this.textCod = textCod;
this.textDes = textDes;
layoutInflater = LayoutInflater.from(context);
}