Reputation: 755
I have create a Java class extending LinearLayout as shown below
public class News extends LinearLayout{
Context context;
public News(Context context) {
super(context);
this.context=context;
ViewFlipper viewFlipper=new ViewFlipper(context);
viewFlipper.setLayoutParams(this.getLayoutParams());
this.addView(viewFlipper);
}
Now is it possible to include this into xml layout like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/com.example.android.apis"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.example.android.apis.view.LabelView
android:background="@drawable/green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:text="Green" app:textColor="#ffffffff" />
</LinearLayout>
Upvotes: 2
Views: 2385
Reputation: 40426
<com.yourcompanyname.projectname.News<<<change here and check path is proper
android:background="@drawable/green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:text="Green" app:textColor="#ffffffff" />
Upvotes: 2
Reputation: 5969
Yes, but you should also override the other constructors as well.
<com.yourproject.package.News
android:background="@drawable/green"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:text="Green" app:textColor="#ffffffff" />
Also, xmlns:app="http://schemas.android.com/apk/res/com.example.android.apis" need to be update to your application package as well.
Upvotes: 1