そのため、作成したカスタム リスト アダプターを動的にしようとしています。最初は空で、ユーザーは項目を動的に追加または削除できます。アダプターを更新するときにアダプターの「getView」が呼び出されないため、アイテムのタイトルが明らかに設定されていません(代わりにアドレスが表示されます)。配列を更新するコードは次のとおりです。
private void newTab(String name, String url){
_tabAdapter.add(new Article(name,url));
_tabAdapter.notifyDataSetChanged();
_tabCount++;
}
アダプター自体のコードは次のとおりです。
public class TabAdapter extends ArrayAdapter<Article>{
Context _context;
@Override
public int getCount() {
return _tabCount;
}
public TabAdapter(Context c) {
super(c, R.layout.tab_item);
_context=c;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) _context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = inflater.inflate(R.layout.tab_item, parent,false);
TextView _itemText = (TextView) _view.findViewById(R.id.tab_text);
Article getArticle = getItem(position);
String newName = getArticle.getName();
_itemText.setText(newName);
return _view;
}
}
これで、他のすべてが正常に機能します。OnClick でさえうまく機能し、アイテムの名前を正しく取得します。アイテムの名前が表示されないのは、リスト自体だけです。かなり基本的なものが欠けているに違いありませんが、それが何であるかがわかりません。どんな助けでも大歓迎です。
更新: 言及された正確な問題の解決策ではありませんが、「記事」クラスの「toString()」メソッドを作成することで回避できました。エレガントなソリューション。