我正在尝试在我的应用程序中实现可扩展的listView,而不是常规的listView ..所有人都可以使用常规listView,但是我不知道如何使用Parse使用可扩展的ListView。com和我找不到任何例子可以帮助我。有人有任何想法吗?
以下是我的常规ListView的代码
public class ListViewPost extends BaseAdapter {
// Declare Variables
Context mContext;
LayoutInflater inflater;
private List<UsersPostsGet> UsersPostsGet = null;
List<ParseObject> ob;
private ArrayList<UsersPostsGet> arraylist;
String reportV;
String XXX;
public int postion;
public ImageLoader imageLoader;
public ListViewPost(Context context, List<UsersPostsGet> UsersPostsGet) {
mContext = context;
this.UsersPostsGet = UsersPostsGet;
inflater = LayoutInflater.from(mContext);
this.arraylist = new ArrayList<UsersPostsGet>();
this.arraylist.addAll(UsersPostsGet);
}
public class ViewHolder {
TextView username;
TextView userpost;
TextView posttime;
ImageView thumbs;
ImageView port;
ImageView stuatsicon;
ImageView attachpic;
}
public int getCount() {
return UsersPostsGet.size();
}
public UsersPostsGet getItem(int position) {
return UsersPostsGet.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.postlayout, null);
// Locate the TextViews in listview_item.xml
holder.username = (TextView) view.findViewById(R.id.nickname);
holder.userpost = (TextView) view.findViewById(R.id.userpost);
holder.posttime = (TextView) view.findViewById(R.id.posttime);
holder.thumbs = (ImageView) view.findViewById(R.id.thumbdown);
holder.stuatsicon = (ImageView) view.findViewById(R.id.statusicon);
holder.port = (ImageView) view.findViewById(R.id.imageView1);
holder.attachpic = (ImageView) view.findViewById(R.id.attachpic);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Set the results into TextViews
holder.username.setText(UsersPostsGet.get(position).getUsername());
holder.userpost.setText(UsersPostsGet.get(position).getUserpost());
holder.posttime.setText(UsersPostsGet.get(position).getPosttime());
ImageLoader imageLoader=new ImageLoader(mContext);
imageLoader.DisplayImage("http://www.nogomistars.com/wallpaper/ahmed-mekki-1898-25363-3138242.jpg", holder.port);
XXX = UsersPostsGet.get(position).getId();
reportV = UsersPostsGet.get(position).getReport();
if (UsersPostsGet.get(position).geturl().contentEquals("")) {
holder.attachpic.setVisibility(View.GONE);
}
if (UsersPostsGet.get(position).getstatus().contentEquals("green")) {
holder.stuatsicon.setImageResource(R.drawable.green2);
}
if (UsersPostsGet.get(position).getstatus().contentEquals("lightgreen")) {
holder.stuatsicon.setImageResource(R.drawable.lightgreenstatus);
}
if (UsersPostsGet.get(position).getstatus().contentEquals("yellow")) {
holder.stuatsicon.setImageResource(R.drawable.yallowstatus);
}
if (UsersPostsGet.get(position).getstatus().toString()
.contentEquals("orange")) {
holder.stuatsicon.setImageResource(R.drawable.orangestatus);
}
if (UsersPostsGet.get(position).getstatus().toString()
.contentEquals("red")) {
holder.stuatsicon.setImageResource(R.drawable.redstatus);
}
if (UsersPostsGet.get(position).getstatus().contentEquals("blue")) {
holder.stuatsicon.setImageResource(R.drawable.bluestatus);
}
// Listen for ListView Item Click
view.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// Send single item click data to SingleItemView Class
Intent intent = new Intent(mContext, SingleItemView.class);
// Pass all data rank
intent.putExtra("username",
(UsersPostsGet.get(position).getUsername()));
intent.putExtra("userpost",
(UsersPostsGet.get(position).getUserpost()));
intent.putExtra("posttime",
(UsersPostsGet.get(position).getPosttime()));
intent.putExtra("status",
(UsersPostsGet.get(position).getstatus()));
intent.putExtra("url",
(UsersPostsGet.get(position).geturl()));
mContext.startActivity(intent);
}
});
return view;
}
}
您无法将Baseadapter用于可扩展的列表视图。创建一个从baseexpandablelistadapter扩展的适配器。GetView()方法应分别替换为GetGroupView()和GetChildView(),分别为组标头视图和子女视图。您可能还需要两个不同的布局来供小组和儿童视图。
这是最好的例子之一。您可以找到许多讨论ExplablElistView的教程。