I'm new to the Android world ... it will be great help if someone fixes me ... what am I doing wrong, the code is below ...
- Requirement: You must create your own view (using the xml layout file) so that the same view is used inside my applications. Here I go with the sample code I'm working on,
cutomviewxml.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Large Text" android:textAppearance="?android:attr/textAppearanceLarge" /> </LinearLayout>
Extended view class ... code ...
mycustomTextview.java
public class mycustomTextview extends View { private View mView; Context mycontext; public mycustomTextview(Context context, AttributeSet attrs) { super(context, attrs);
Action file main.xml
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <com.motorola.mycustomTextview android:id="@+id/customtextview" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@+id/textView2" android:layout_marginLeft="143dp" android:layout_marginTop="69dp" android:layout_toRightOf="@+id/textView1" /> </RelativeLayout>
Action class sample.java ..
public class sample extends Activity{ private static final String LOG_TAG = "sampleActivity"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i(LOG_TAG,"OnCreate of sampleActivity"); setContentView(R.layout.main); } }
source share