如何在listview中获取所选项目,我有listview与arrayadapter,listview包含26项,但我只需显示6项,另一项显示在更多按钮。我怎么能得到这个。 请帮我。在此先感谢.....!
MainActivity.java
公共类SelectProtocolActivity扩展了Activity {
ListView listview;
ListViewArrayAdapter arrayadapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
listview = (ListView) findViewById(R.id.protocol_list_view);
db = DatabaseHelper.getHelper(getApplicationContext());
protocols = db.getAllProtocolsList();
arrayadapter = new ListViewArrayAdapter(this, protocols);
listview.setAdapter(arrayadapter);
listview.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id){
}
});
}
}
ListViewArrayAdapter.java
public class ListViewArrayAdapter extends BaseAdapter implements ListAdapter {
private final Activity activity;
private final List<Item> itemList;
ProtocolArrayAdapter(Activity activity, List<Items> itemList) {
assert activity != null;
assert protocolList != null;
this.itemList = itemList;
this.activity = activity;
}
@Override
public int getCount() {
if (null == itemList)
return 0;
else
return itemList.size();
}
@Override
public Item getItem(int position) {
if (null == itemList)
return null;
else
return itemList.get(position);
}
@Override
public long getItemId(int position) {
//Protocol protocol = getItem(position);
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null)
convertView = activity.getLayoutInflater().inflate(R.layout.item_list_item, null);
TextView tvItemName = (TextView) convertView.findViewById(R.id.item_name);
Item item = getItem(position);
if (null != item) {
try {
tvItemName.setText(item.getName());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return convertView;
}
}
答案 0 :(得分:0)
请仔细阅读希望说明帮助您
您可以通过多种方式实现可以在此处使用可扩展列表视图或
的东西我认为你为那个Bean类加了一个布尔变量名(isOpen)。 默认情况下,值为false 应用点击事件查看更多按钮 根据
设计行项目XML分隔布局中的6个项目和分开的20个项目。
20项目布局可见性默认为GONE
比列表视图中点击查看更多根据位置设置isOpen = true 和notifydata设置改变。
并在适配器中进行参数化设置isOpen = true您的20项布局是可见的其他副作用