gpt4 book ai didi

android - 如果为空,则更改 ListView 布局

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

<分区>

我使用适配器来设置项目布局并从 JSON 字符串填充 ListView。有时这个 JSON 是空的,ListView 中没有任何行,它完全是空白的。

在这种情况下,我想更改 View 并传递显示“此处没有任何行”的另一个布局。

所以这是我的代码:

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);
}

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