android-api-graph_flow icon indicating copy to clipboard operation
android-api-graph_flow copied to clipboard

Implementing a custom xml based view

Open bmbariah opened this issue 8 years ago • 1 comments

Hi, thanks for this.

Can you provide a guide on how I can have a Node with a Class<?> descriptor, that has an xml layout and multiple edittext's. Maybe a login perhaps...for example.

bmbariah avatar Jul 17 '17 08:07 bmbariah

Im gonna try. Currently im overloaded with stuff so its gonna be impossible.

To create a node with a view just do like this:

  1. Add this dependency to use views instead of fragments or conductor compile "com.saantiaguilera.graphflow:views:<latest_version>"
  2. Use as node switcher a view one new NodeViewSwitcher(context, R.id.container_of_the_graph_flow);
  3. Create nodes with Class<? extends View>. In your case it should be a view that has an xml layout and multiple edittexts. My guess would be something like this:
public class MyViewContainer extends LinearLayout /* or wver you want */ {
  public MyViewContainer(Context context) {
    this(context, null);
  }
  public MyViewContainer(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }
  public MyViewContainer(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    setOrientation(VERTICAL); // And customize, since this view will not be wrapped in another xml? Of course if this is not the case, dont use merge

    inflate(context, R.layout.your_layout_with_merge_root_node, this);
     
    EditText editText = findViewById(R.id.smth);
    EditText editText2 = findViewById(R.id.value);
  }
  // Whatever else.. Refactor it obviously!
}
<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" >

    <EditText
        android:id="@+id/smth"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="EditText"
        android:textColor="#000"/>

    <EditText
        android:id="@+id/value"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:textColor="#000"/>

</merge>

And thats it. The testapp has an example like this, although its all coupled and really ugly (because I did it hella fast)

As soon as Im free im gonna update the docs with better examples :)

saantiaguilera avatar Jul 18 '17 18:07 saantiaguilera