我已经有一个列表视图,我想将其转换为可扩展的列表视图
Posted
技术标签:
【中文标题】我已经有一个列表视图,我想将其转换为可扩展的列表视图【英文标题】:I already have a listview i want to convert it into expandable ListView 【发布时间】:2015-06-28 03:33:45 【问题描述】:以下是我的基本适配器代码。我将使用这个类作为ListView
的适配器。
public class CustombaseAdapterTxnCartSelect extends BaseAdapter
private Context mContext;
private List<RowItemTxnCartSelect> mRowItems;
TextView standDesc, seats, totalTicketTariff, eventDesc;
public CustombaseAdapterTxnCartSelect(Context context, List<RowItemTxnCartSelect> rowItems)
mContext = context;
mRowItems = rowItems;
@Override
public int getCount()
return mRowItems.size();
@Override
public Object getItem(int position)
return mRowItems.get(position);
@Override
public long getItemId(int position)
return mRowItems.indexOf(getItem(position));
@Override
public View getView(int position, View convertView, ViewGroup parent)
convertView = null;
LayoutInflater mInflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = mInflator.inflate(R.layout.event_layout_txn__cart_select, null);
standDesc = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectStandDesc);
seats = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectSeats);
totalTicketTariff = (TextView) convertView.findViewById(R.id.textViewTxnCartSelectTotalTicketTariff);
eventDesc = (TextView) convertView.findViewById(R.id.textViewEventDesc);
RowItemTxnCartSelect row = (RowItemTxnCartSelect) getItem(position);
standDesc.setText(row.getmStandDesc());
seats.setText(row.getmSeats());
totalTicketTariff.setText(row.getMtotalTicketTariff());
eventDesc.setText(row.getmEventDesc());
return convertView;
我只是想把它转换成一个可扩展的列表视图我不清楚我要添加什么。
【问题讨论】:
代码整理。一些语法修复。 【参考方案1】:也许你可以这样:
public class FevList extends ExpandableListActivity
String title;
String url;
SQLiteDatabase database;
DbUtil db;
HashMap<String, String> map = new HashMap<String, String>();
ArrayList<HashMap<String, String>> subjectList = new ArrayList<HashMap<String, String>>();
@SuppressWarnings("unchecked")
@Override
protected void onCreate(Bundle savedInstanceState)
try
super.onCreate(savedInstanceState);
setContentView(R.layout.exlist);
db = new DbUtil();
database = db.openConnection(this);
// Thread for getting values of title from DataBase.
SimpleExpandableListAdapter expListAdapter = new SimpleExpandableListAdapter(
this, createGroupList(), R.layout.group_row,
new String[] "subject" , new int[] R.id.row_name ,
createChildList(), R.layout.child_row,
new String[] "title" , new int[] R.id.grp_child );
setListAdapter(expListAdapter);
registerForContextMenu(getExpandableListView());
catch (Exception e)
e.printStackTrace();
// 适配器代码
/* 为行创建 Hashmap */ ArrayList> 结果 = 新的 ArrayList>();
@SuppressWarnings("unchecked")
private List createGroupList()
// write your code here.
return (List) result;
/* creatin the HashMap for the children */
@SuppressWarnings("unchecked")
private List createChildList()
// write your code here.
return result;
public void onContentChanged()
System.out.println("onContentChanged");
super.onContentChanged();
/* This function is called on each child click */
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id)
// write your code here.
return true;
/* This function is called on expansion of the group */
public void onGroupExpand(int groupPosition)
try
System.out.println("Group exapanding Listener => groupPosition = "
+ groupPosition);
catch (Exception e)
System.out.println(" groupPosition Errrr +++ " + e.getMessage());
这是一个sn-p,你可以参考this
【讨论】:
【参考方案2】:Here 是一个开源示例项目,用于演示 ExpandableListView。这是开始使用可扩展列表视图的好例子。
【讨论】:
以上是关于我已经有一个列表视图,我想将其转换为可扩展的列表视图的主要内容,如果未能解决你的问题,请参考以下文章
将 pandas Dataframe 的行转换为可迭代的字符串列表