在我正在开发的应用程序中,我得到了一个带有标题数据等的消息列表。当单击消息标题时,我想滑动展开此条目并显示详细信息,以及一些新按钮,如“回复”、“删除”和“转发” .
喜欢:
- 消息
- 消息(点击消息)
详细信息按钮删除,转发,回复
文本
- 消息
- 消息
这是我到目前为止所做的:
首先是我的模型类的消息:
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() 我不知道为什么。
我在使用服装适配器时犯了什么大错误吗?提前致谢