package com.sunnyrao.treeview;

import java.util.ArrayList;
import java.util.List;

import com.sunnyrao.treeview.adapter.SimpleTreeListViewAdapter;
import com.sunnyrao.treeview.bean.FileBean;
import com.sunnyrao.treeview.utils.Node;
import com.sunnyrao.treeview.utils.adapter.TreeListViewAdapter;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity {

	private ListView mTree;
	private SimpleTreeListViewAdapter<FileBean> mAdapter;
	private List<FileBean> mData;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		mTree = (ListView) findViewById(R.id.id_listView);

		initDatas();
		try {
			mAdapter = new SimpleTreeListViewAdapter<FileBean>(mTree, this,
					mData, 0);
			mTree.setAdapter(mAdapter);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}

		initEvent();

	}

	private void initEvent() {
		mAdapter.setOnTreeNodeClickListener(new TreeListViewAdapter.OnTreeNodeClickListener() {
			@Override
			public void onClick(Node node, int position) {
				if (node.isLeaf()) {
					Toast.makeText(MainActivity.this, node.getName(),
							Toast.LENGTH_SHORT).show();
				}
			}
		});

		mTree.setOnItemLongClickListener(new OnItemLongClickListener() {
			@Override
			public boolean onItemLongClick(AdapterView<?> parent, View view,
					final int position, long id) {
				// DialogFragment
				final EditText et = new EditText(MainActivity.this);
				new AlertDialog.Builder(MainActivity.this).setTitle("Add Node")
						.setView(et)
						.setPositiveButton("Sure", new OnClickListener() {
							@Override
							public void onClick(DialogInterface dialog,
									int which) {
								if (TextUtils.isEmpty(et.getText().toString()))
									return;
								mAdapter.addExtraNode(position, et.getText()
										.toString());
							}
						}).setNegativeButton("Cancel", null).show();

				return true;
			}
		});
	}

	private void initDatas() {
		mData = new ArrayList<FileBean>();
		FileBean bean = new FileBean(1, 0, "Ŀ¼1");
		mData.add(bean);
		bean = new FileBean(2, 0, "Ŀ¼2");
		mData.add(bean);
		bean = new FileBean(3, 0, "Ŀ¼3");
		mData.add(bean);
		bean = new FileBean(4, 1, "Ŀ¼1-1");
		mData.add(bean);
		bean = new FileBean(5, 1, "Ŀ¼1-2");
		mData.add(bean);
		bean = new FileBean(6, 5, "Ŀ¼1-2-1");
		mData.add(bean);
		bean = new FileBean(7, 3, "Ŀ¼3-1");
		mData.add(bean);
		bean = new FileBean(8, 3, "Ŀ¼3-2");
		mData.add(bean);
	}
}

@@ -2459,18 +2459,19 @@
 (1, 0, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 1%22);%0A%09%09m
@@ -2515,18 +2515,19 @@
 (2, 0, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 2%22);%0A%09%09m
@@ -2571,18 +2571,19 @@
 (3, 0, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 3%22);%0A%09%09m
@@ -2627,18 +2627,19 @@
 (4, 1, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 1-1%22);%0A%09
@@ -2685,18 +2685,19 @@
 (5, 1, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 1-2%22);%0A%09
@@ -2743,18 +2743,19 @@
 (6, 5, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 1-2-1%22);
@@ -2803,18 +2803,19 @@
 (7, 3, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 3-1%22);%0A%09
@@ -2865,10 +2865,11 @@
 3, %22
-%C4%BF%C2%BC
+%E6%A0%B9%E7%9B%AE%E5%BD%95
 3-2%22

Update MainActivity.java