Android 如何使用自定义pojo类列表在微调器中设置特定项?
我是Android编程新手,我想知道如何添加一个项目下拉列表,我已经尝试过了,但这并不完全是我所需要的 例如,我想在下拉列表中添加0位置添加所有值 我是这样的Android 如何使用自定义pojo类列表在微调器中设置特定项?,android,performance,android-layout,android-activity,Android,Performance,Android Layout,Android Activity,我是Android编程新手,我想知道如何添加一个项目下拉列表,我已经尝试过了,但这并不完全是我所需要的 例如,我想在下拉列表中添加0位置添加所有值 我是这样的 Song1 song2 但我想得到这样的输出 ALL song1 song2 这是我的源代码 //Here Song - Pojo class //songlist - List Instance values retrieved from DB ContentSearchAdapterComposer adpter
Song1
song2
但我想得到这样的输出
ALL
song1
song2
这是我的源代码
//Here Song - Pojo class
//songlist - List Instance values retrieved from DB
ContentSearchAdapterComposer adptercopmposer;
artistList =new ArrayList<ArtistList>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contentsearch);
initialization();
daoSession = MApplication.getSessionWrite(ContentSearch.this);
artist_ListDao =daoSession.getArtistListDao();
artistList =artist_ListDao.loadAll();
}
为什么在son_标题中使用getposition.getTitle 也许你应该使用:
holder.title.setText(son_title.getTitle());
对吗?首先在getView方法中进行如下更改
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listitem, null);
holder = new ViewHolder();
holder.title = (TextView) convertView.findViewById(R.id.title);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Song son_title = mList.get(position);
holder.title.setText(son_title.getTitle());
return convertView;
}
其次,要将所有元素显示为第一个元素,您应该初始化您的歌曲类,在添加元素时使用所有文本将其称为pojo,然后在其中添加歌曲id或与歌曲相关的数据
第三,在getCount方法中做以下更改
public int getCount() {
return mList != null ? mList.size() : 0;
}
请让我知道这是否有帮助 您可以在构造函数调用中这样做
public CustomListAdapter(Context context,List<Song> results) {
mList = results;
Song ALL = new Song();
ALL.setTitle("ALL");
mList.add(0,ALL);
mInflater = LayoutInflater.from(context);
}
因此,在您的下拉列表中,结构将如下所示:ALL,Song1,Song2…如何在其中添加项目?如何在Listsonglist=new ArrayList;中添加数据?已经添加了下拉列表,但我的问题是在微调器中添加一项?将代码张贴在列表中添加数据的位置,然后将列表传递到此微调器适配器SongList=songDao.loadAll;儿子的意思是宋伯乔班对儿子全部=新儿子;对不起,这不是我的儿子。这正是宋波乔班@库玛