0
    <android.support.v7.widget.RecyclerView
        android:id="@+id/menu_list_rv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        >

    </android.support.v7.widget.RecyclerView>

Consider example of RecyclerView we put above code in xml and create its instance in java class like this

menuListRV      = (RecyclerView)findViewById(R.id.sugg_rv);

After this we can control it anyway we want.

Now my question is how can create my own xml tag <xyz></xyz> may be with some proprties and associate a class XYZ to it.

UPDATE

I am getting the mediaplayer view but when I am attaching a xml to it I am not getting change infact I think xml view is not rendered itself.

public class ShortMediaPlayerControl extends ViewGroup {

    public ShortMediaPlayerControl(Context context, AttributeSet attrs) {
        super(context, attrs);
        inflate(context);
        Toast.makeText(context, "Coming 2", Toast.LENGTH_SHORT).show();
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ShortMediaPlayerControl, 0, 0);
    }


    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {

    }

    private void inflate(Context context) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.short_media_player, this, true);
    }

}
RateM
  • 241
  • 1
  • 4
  • 15

1 Answers1

0

You need to create class, inherited from needed widget. In your case this is RecyclerView.

public class MyCustomRecyclerView extends RecyclerView {
    ...
}

And then you can use it in xml like this:

 <com.example.yourapp.MyCustomRecyclerView 
    ...
           />

UPDATE

Maybe late, but looks like i figured out what do you mean. So yes, you can associate your custom widget class with xml like this:

public class MyCustomRecyclerView extends RecyclerView {
        ...
    private void init(final Context context) {
        inflate(context, R.layout.your_custom_recycler_view_layout, this);
        ...
    }
}
Phileas
  • 69
  • 9
  • can we use xml with new class? – RateM Nov 09 '19 at 12:31
  • @RateM, what do you mean? If your class extends layouts or widgets - yes, you can use them in layout xml. Just try to create your class, add required constructors and methods (they can be different depending on the type), and then in your layout xml you can use your widget, where tag will be full package name of your class. – Phileas Nov 09 '19 at 12:54