I nested in ExpandableListView in ExpandableListView
Is nested in the ExpandableListView child can not open
Only a child can not be changed so high high
main class
package R.M.activity;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import R.M.R;
import R.M.adapter.rmAdapter;
import android.app.ExpandableListActivity;
import android.os.Bundle;
public class MainActivity extends ExpandableListActivity {
/ ** Called when the activity is first created. * /
String rootpath = "/";
@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
File root = new File (rootpath);
File [] files = root.listFiles ();
Listchild = new ArrayList ();
for (File file: files) {
child.add (file.listFiles ());
}
setListAdapter (new rmAdapter (files, child, this));
}
}
adapter
package R.M.adapter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import R.M.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.TextView;
/ **
* @ Author yubin
* @ Version 2012-4-10 07:37:49
pm** /
public class rmAdapter extends BaseExpandableListAdapter {
File [] parentfiles = new File [1];
Listchildlist = new ArrayList ();
Context context;
LayoutInflater inflater;
public rmAdapter (File [] p, Listc, Context con) {
parentfiles = p;
childlist = c;
context = con;
}
@ Override
public File getChild (int groupPosition, int childPosition) {
return childlist.get (groupPosition) [childPosition];
}
@ Override
public long getChildId (int groupPosition, int childPosition) {
return childPosition;
}
@ Override
public int getChildrenCount (int groupPosition) {
return childlist.get (groupPosition)! = null? childlist
. Get (groupPosition) length:. 0;
}
@ Override
public File getGroup (int groupPosition) {
return parentfiles [groupPosition];
}
@ Override
public int getGroupCount () {
return parentfiles.length;
}
@ Override
public long getGroupId (int groupPosition) {
return groupPosition;
}
@ Override
public boolean hasStableIds () {
return true;
}
@ Override
public boolean isChildSelectable (int groupPosition, int childPosition) {
return true;
}
@ Override
public View getGroupView (int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
inflater = (LayoutInflater) context
. GetSystemService (Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate (R.layout.parent, null);
parentitem p = new parentitem ();
p.tvp = (TextView) convertView.findViewById (R.id.tvparent);
p.tvp.setText (parentfiles [groupPosition] getName ().);
return convertView;
}
class parentitem {
TextView tvp;
}
@ Override
public View getChildView (int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (childlist.get (groupPosition) [childPosition]. isDirectory ()) {
inflater = (LayoutInflater) context
. GetSystemService (Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate (R.layout.childfile, null);
ExpandableListView elv = (ExpandableListView) convertView
. FindViewById (R.id.elvmain);
File [] parentfile = childlist.get (groupPosition) [childPosition]
. ListFiles ();
Listchildfile = new ArrayList ();
for (File file: parentfile) {
childfile.add (file.listFiles ());
}
elv.setAdapter (new rmAdapter (parentfile, childfile, context));
}
else {
inflater = (LayoutInflater) context
. GetSystemService (Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate (R.layout.child, null);
parentitem p = new parentitem ();
p.tvp = (TextView) convertView.findViewById (R.id.tvchild);
p.tvp.setText (childlist.get (groupPosition) [childPosition] getName ().);
}
return convertView;
}
}
main class XML
xmlns: android = "http://schemas.android.com/apk/res/android"
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: background = "# ffffff">android: id = "@ id / android: list"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: fadingEdge = "none">
children of ExpandableListView's XML
xmlns: android = "http://schemas.android.com/apk/res/android"
android: orientation = "vertical"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: background = "# ffffff">android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: layout_marginLeft = "40dip">android: id = "@ + id / elvmain"
android: layout_width = "fill_parent"
android: layout_height = "wrap_content"
android: fadingEdge = "none">
Reply:
Reply:
Reply:
Reply:
Is no one will do?
Reply:
Go look at this
http://blog.csdn.net/jasonzhou613/article/details/7892891
I just solved a similar problem, I hope useful to you.
Reply:
Will you not solve ah
Reply:
That just sets a layer of me that is not useful to determine the set of layers or wood
But thank you
Posts to not end up divided

Reply:
Landlord solved? I have encountered this problem
Reply:
Finally, how to get ah?
No comments:
Post a Comment