作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我创建了包含一个问题和四个选项的数据库和表“TABLE_NAME”。
我的问题是如何在 ListView 中用选项显示这个问题。
我搜索了很多文章,但找不到一次添加 5 项的合适方法。
请提供一些引用或代码。
我正在尝试使用可扩展 ListView 。但它不显示问题,只显示
4个选项中的一个。
这是我的示例代码。
public class ObjectiveExamActivity extends ExpandableListActivity {
@SuppressWarnings("unchecked")
public void onCreate(Bundle savedInstanceState) {
try{
super.onCreate(savedInstanceState);
setContentView(R.layout.displayobjectiveque);
Intent intent=getIntent();
setResult(RESULT_OK, intent);
SimpleExpandableListAdapter expListAdapter =
new SimpleExpandableListAdapter(
this,
createGroupList(),
R.layout.group_row,
new String[] { "Group Item" },
new int[] { R.id.row_name },
createChildList(),
R.layout.child_row,
new String[] {"Sub Item"},
new int[] { R.id.grp_child}
);
setListAdapter( expListAdapter );
}catch(Exception e){
System.out.println("Error+++ " + e.getMessage());
}
}
@SuppressWarnings("unchecked")
private List createGroupList() {
ArrayList result = new ArrayList();
final MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
final List<ObjectiveWiseQuestion> LocWiseProfile= m.getAllObjectiveQuestion();
for (final ObjectiveWiseQuestion cn : LocWiseProfile)
{
HashMap m1=new HashMap();
m1.put("Item","Option:"+cn.getQuestion());
result.add(m1);
}
/* for( int i = 0 ; i < 15 ; ++i ) { // 15 groups........
HashMap m = new HashMap();
m.put( "Group Item","Group Item " + i ); // the key and it's value.
result.add( m );
}*/
return (List)result;
}
@SuppressWarnings("unchecked")
private List createChildList()
{
final MySQLiteHelper m=new MySQLiteHelper(getBaseContext());
final List<ObjectiveWiseQuestion> LocWiseProfile= m.getAllObjectiveQuestion();
ArrayList result = new ArrayList();
for (final ObjectiveWiseQuestion cn : LocWiseProfile)
{ // this -15 is the number of groups(Here it's fifteen)
/* each group need each HashMap-Here for each group we have 3 subgroups */
ArrayList secList = new ArrayList();
for( int n = 0 ; n < 4 ; n++ )
{
HashMap child = new HashMap();
child.put( "Sub Item", "Sub Item " + m.getAllObjectiveQuestion() );
child.put(cn.getOptionA(), cn.getOptionB());
child.put("Option C", cn.getOptionC());
child.put("Option D", cn.getOptionD());
secList.add( child );
}
result.add( secList );
}
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) {
System.out.println("Inside onChildClick at groupPosition = " + groupPosition +" Child clicked at position " + childPosition);
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());
}
}
提前致谢。
最佳答案
Expandable ListView可以是你的作品。
关于android - 如何在ListView中添加一个有四个选项的项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9766844/
我是一名优秀的程序员,十分优秀!