在App im开发中,我得到了一个带有titel datum等的消息列表。 当点击Messagetitel我想要滑动展开此条目并显示详细信息,以及一些新的按钮,如“回复”,“删除”和“转发”。
像:
- 留言
- 消息(点击消息)
详情按钮删除,转发,回复
文字
- 留言
- 消息
这是我到目前为止所做的:
首先是我的消息模型类:
public class MyMessage {
private String from;
private String subject;
private String date;
private String message;
public MyMessage(String f, String s, String d, String m){
from= f;
subject= s;
date = d;
message= m;
}
public String getFrom() {
return from;
}
public String getSubject() {
return subject;
}
public String getDate() {
return date;
}
public String getMessage() {
return message;
}
}
我的自定义适配器:
public class NewAdapter extends BaseExpandableListAdapter {
public ArrayList<MyMessage> mMessage;
public LayoutInflater minflater;
public Activity activity;
public NewAdapter(ArrayList<MyMessage> message){
mMessage = message;
}
public void setInflater(LayoutInflater mInflater, Activity act) {
this.minflater = mInflater;
activity = act;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
TextView text = null;
// TODO Auto-generated method stub
if (convertView == null) {
convertView = minflater.inflate(R.layout.message_details, null);
}
text = (TextView) convertView.findViewById(R.id.tv_message_text);
text.setText(mMessage.get(childPosition).getMessage());
return convertView;
}
@Override
public int getChildrenCount(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public Object getGroup(int groupPosition) {
// TODO Auto-generated method stub
return null;
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return 0;
}
@Override
public long getGroupId(int groupPosition) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
TextView from= null;
TextView date = null;
TextView subject= null;
// TODO Auto-generated method stub
if(convertView == null){
convertView = minflater.inflate(R.layout.message_head, null);
}
from= (TextView) convertView.findViewById(R.id.tv_from);
date = (TextView) convertView.findViewById(R.id.tv_date);
subject= (TextView) convertView.findViewById(R.id.tv_subject);
from.setText(mMessage.get(groupPosition).getfrom());
date.setText(mMessage.get(groupPosition).getDate());
subject.setText(mMessage.get(groupPosition).getSubject());
return convertView;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return false;
}
}
我的主要班级:
public class Test extends ExpandableListActivity{
public ArrayList<MyMessage> message;
public ExpandableListView eListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
eListView = getExpandableListView();
message = createMessages();
NewAdapter nAdapter = new NewAdapter(message);
nAdapter
.setInflater(
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE),
this);
getExpandableListView().setAdapter(nAdapter);
}
private ArrayList<MyMessage> createMessages() {
ArrayList<MyMessage> m = new ArrayList<MyMessage>();
MyMessage test1 = new MyMessage("test1", "testbetreff", "08.11.2013 / 09:44", "gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so");
MyMessage test2 = new MyMessage("test2", "testbetreff", "08.11.2013 / 09:45", "gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so");
MyMessage test3 = new MyMessage("test3", "testbetreff", "08.11.2013 / 09:46", "gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so");
MyMessage test4 = new MyMessage("test4", "testbetreff", "08.11.2013 / 09:47", "gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaanz viel text und so");
m.add(test1);
m.add(test2);
m.add(test3);
m.add(test4);
return m;
}
}
我没有收到任何错误,但我的活动是空白的。我试图调试这个,但它从不调用getchildview()或getgroupview(),我不知道为什么。
我是否正在使用costum适配器做任何重大错误? 提前谢谢
答案 0 :(得分:0)
@Override
public int getChildrenCount(int groupPosition) {
return 1; //just one children?
}
@Override
public Object getGroup(int groupPosition) {
return mMessage.get(groupPosition);
}
@Override
public int getGroupCount() {
return mMessage.size();
}
@Override
public long getGroupId(int groupPosition) {
return groupPosition;
}
试试这个......也许它没有被调用,因为你说适配器根本没有任何物品......