Слева исходная база данных, справа - дерево в андроиде.
Внешний вид не причесан еще.
Все открывается-закрывается.

Если у кого-то появятся вопросы по нему, с удовольствием отвечу )

Код: Выделить всё
import java.sql.Date;
public class Deposit {
private long deposit_id;
private long client_id;
private double balance;
private String type;
private double estimated_balance;
private Date opening_date;
private Date closing_date;
public Deposit() {
}
public Deposit(long deposit_id, long client_id, double balacne,
String type, long estimated_balance, Date opening_date,
Date closing_date) {
super();
this.deposit_id = deposit_id;
this.client_id = client_id;
this.balance = balacne;
this.type = type;
this.estimated_balance = estimated_balance;
this.opening_date = opening_date;
this.closing_date = closing_date;
}
public long getDeposit_id() {
return deposit_id;
}
public void setDeposit_id(long deposit_id) {
this.deposit_id = deposit_id;
}
public long getClient_id() {
return client_id;
}
public void setClient_id(long client_id) {
this.client_id = client_id;
}
public double getBalance() {
return balance;
}
public void setBalance(double balacne) {
this.balance = balacne;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getEstimated_balance() {
return estimated_balance;
}
public void setEstimated_balance(double d) {
this.estimated_balance = d;
}
public Date getOpening_date() {
return opening_date;
}
public void setOpening_date(Date date) {
this.opening_date = date;
}
public Date getClosing_date() {
return closing_date;
}
public void setClosing_date(Date date) {
this.closing_date = date;
}
}
Код: Выделить всё
public class DepositsFragment extends Fragment {
private static final String CHILD_NAME = "childName";
private static final String GROUP_NAME = "groupName";
// collection for groups
private ArrayList<Map<String, String>> groupData;
// collection for elements of one group
private ArrayList<Map<String, String>> childDataItem;
// general collection for element's collection
private ArrayList<ArrayList<Map<String, String>>> childData;
// we will get childData = ArrayList<childDataItem>
// list of attributes for group or element
private Map<String, String> elementMap;
private SimpleExpandableListAdapter expandableListAdapter;
private ExpandableListView expandableListView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_deposits, null);
List<Deposit> deposits = ClientContainer.getClientContainer()
.getDeposits();
groupData = new ArrayList<Map<String, String>>();
for (Deposit deposit : deposits) {
Log.d(MbankMainActivity.MBANK_CLIENT,
"DepositsFragment.onCreateView adding deposit type: "
+ deposit.getType());
// fill the list of attributes for each map
elementMap = new HashMap<String, String>();
elementMap.put(GROUP_NAME, "Deposit type: " + deposit.getType());
groupData.add(elementMap);
}
// create collection for elements collection
childData = new ArrayList<ArrayList<Map<String, String>>>();
for (Deposit deposit : deposits) {
// create collection of elements for first group
childDataItem = new ArrayList<Map<String, String>>();
elementMap = new HashMap<String, String>();
elementMap.put(CHILD_NAME,
"Current Balance " + deposit.getBalance()); // balance
childDataItem.add(elementMap);
elementMap = new HashMap<String, String>();
elementMap.put(CHILD_NAME,
"Estimated balance " + deposit.getEstimated_balance()); // estimated
// balance
childDataItem.add(elementMap);
elementMap = new HashMap<String, String>();
elementMap.put(CHILD_NAME,
"Opening Date " + deposit.getOpening_date()); // Opening
// Date
childDataItem.add(elementMap);
elementMap = new HashMap<String, String>();
elementMap.put(CHILD_NAME,
"Closing Date " + deposit.getClosing_date()); // Closing
// Date
childDataItem.add(elementMap);
// adding to collection of collection
childData.add(childDataItem);
}
// list of attributes for reading
String groupFrom[] = new String[] { GROUP_NAME };
// list of ID view-elements, to which you will pass the attributes of
// the group
int[] groupTo = new int[] { android.R.id.text1 };
// List of attributes for reading
String childFrom[] = new String[] { CHILD_NAME };
// list of ID view-elements, to which you will place attributes
int childTo[] = new int[] { android.R.id.text1 };
expandableListAdapter = new SimpleExpandableListAdapter(getActivity(),
groupData, android.R.layout.simple_expandable_list_item_1,
groupFrom, groupTo, childData, R.layout.text_item, childFrom,
childTo);
expandableListView = (ExpandableListView) view
.findViewById(R.id.elv_Deposits);
expandableListView.setAdapter(expandableListAdapter);
return view;
}
}
данные пока "встроенные из примера" , теоритически разобрался, это будет следующий этапFoenix писал(а):У меня тоже дерево в фрагменте, если будет актуально и проект запустится посмотрю вечером, у меня на ноуте нет эклипса.
Данные откуда берешь?
Без фрагмента, просто на активити получилоь дерево построить? ТАм основная трудность запихнуть в него данные, в этом разобрался?
это кусок составлен из 2-х стронних примеров, комментарии оставлены как в оригиналах...Foenix писал(а):Посмотрела проект, слишком много лишнего наворочено, ни одного комментария что там где, извини, это слишком много времени нужно убить, чтоб во всем разобраться.
layout fragment2 вообще не открылся посмотреть что там. Куча каких-то библиотек, ни одного активити сходу не нашла..
Просто когда даешь проекты другим, нужно максимально упрощать пример, комментарии, главная активити, в общем - все по стандарту.
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:treeView="http://schemas.android.com/apk/res/pl.polidea.treeview"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="0dip"
android:layout_height="0dip"
android:scrollbars="vertical"
android:visibility="gone"> <!-- Just to test some attributes in IDE -->
</ListView>
<pl.polidea.treeview.TreeViewList
android:id="@+id/mainTreeView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
treeView:indicator_gravity="right|center_vertical"
android:scrollbars="vertical"
android:smoothScrollbar="true"/>
</LinearLayout>Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#A55"
android:id="@id/fr2rl">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txt1"
android:id="@+id/textView"/>
</RelativeLayout>
Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#A55"
android:id="@id/fr2rl">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/txt1"
android:id="@+id/textView"/>
<view
android:layout_width="match_parent"
android:layout_height="match_parent"
class="treeview.TreeViewList"
android:id="@id/TreeViewFr"
android:layout_alignParentTop="false"
android:layout_below="@+id/textView"/>
</RelativeLayout>Код: Выделить всё
<treeview.TreeViewList
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="false"
android:layout_below="@+id/textView"
indicator_gravity="right|center_vertical"
android:id="@id/mainTreeView"
android:background="#fff1e5"
style="@style/treeViewListStyle" />Код: Выделить всё
<?xml version="1.0" encoding="utf-8"?>
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@android:drawable/divider_horizontal_dark"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:scaleType="fitXY" android:paddingLeft="5sp"
android:paddingRight="5sp" android:paddingBottom="2sp"/>в последнем (X1_3) лишнее убрано(кроме x_act в папке меню, но меню пока ни где не нужно).Foenix писал(а):Убери вообще весь мусор из проекта, оставь только дерево и его появление - для того чтоб именно протестировать и не отвлекаться на другое.
Плюс еще - покажи работающее дерево, где нет фрагмента?
Код: Выделить всё
//анимация
fragment1 = new Fragment1();//пустой фрагмент
fragment2 = new Fragment2();//фрагмент с деревом
ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.animator.slide_in_left1, R.animator.slide_in_right1);
ft.replace(R.id.fragCont, fragment1);
ft.addToBackStack(null);
ft.commit();Код: Выделить всё
/ищем тескст
tview= (TextView) findViewById( R.id.view1);
//определяем листенер и его действия (смена фрагментов)
OnClickListener click1= new OnClickListener(){
@Override
public void onClick(View v) {
ft = getFragmentManager().beginTransaction();
if(fragment1.isVisible()){
ft.setCustomAnimations( R.animator.slide_in_right2,R.animator.slide_in_left1);
ft.replace(R.id.fragCont, fragment2);
}else{
ft.setCustomAnimations( R.animator.slide_in_right1,R.animator.slide_in_left2);
ft.replace(R.id.fragCont, fragment1);
}
ft.commit();
}
};
//назначаем листенер тексту
tview.setOnClickListener(click1);