android


Android custom Edit Text View Error


i have created a project named NewApplication and activity class and activity xml are:
public class NewActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_new);
ActionBar Abar=getActionBar();
Abar.setIcon(R.drawable.login_logo);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_new, menu);
return super.onCreateOptionsMenu(menu);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_search:
return true;
case R.id.action_location_found:
LocationFound();
return true;
case R.id.action_refresh:
return true;
case R.id.Check_update:
return true;
default:
return super.onOptionsItemSelected(item);
}
}
private void LocationFound(){
startActivity(new Intent(NewActivity.this,LocationFound.class));
}
public void startplay(View view){
ProgressBar Bar=(ProgressBar)findViewById(R.id.sign_in_loading_spinner);
Bar.setVisibility(View.VISIBLE);
}
}
and this is project main activity xml file
<RelativeLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/login_background"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="#+id/Back_imag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:focusable="true"
android:paddingBottom="#dimen/padding_large"
android:src="#drawable/login_logo"
android:contentDescription="#string/login_image">
<requestFocus />
</ImageView>
<FrameLayout
android:id="#+id/email_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/Back_imag"
android:layout_alignLeft="#+id/Back_imag"
android:layout_alignRight="#+id/Back_imag"
android:layout_below="#+id/Back_imag"
android:layout_alignStart="#+id/Back_imag"
android:paddingBottom="#dimen/padding_large">
<com.example.hp.newapplication.EditTextPushContent
android:id="#+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="#dimen/signin_edittext_height"
style="#style/login_edittext"
android:layout_gravity="center_horizontal|center_vertical"
android:focusableInTouchMode="true"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="#string/login_email_hint"
app:anchorId="#+id/Sign_in_button"/>
</FrameLayout>
<FrameLayout
android:id="#+id/password_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="#dimen/padding_large"
android:layout_alignEnd="#id/email_frame_layout"
android:layout_alignLeft="#id/email_frame_layout"
android:layout_alignStart="#id/email_frame_layout"
android:layout_alignRight="#id/email_frame_layout"
android:layout_below="#id/email_frame_layout">
<com.example.hp.newapplication.EditTextPushContent
android:id="#+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="#dimen/signin_edittext_height"
style="#style/login_edittext"
android:ems="10"
android:layout_gravity="center_horizontal|center_vertical"
app:anchorId="#+id/Sign_in_button"
android:focusableInTouchMode="true"
android:inputType="textPassword"
android:imeOptions="actionGo"
android:hint="#string/login_password_hint"/>
</FrameLayout>
<FrameLayout
android:id="#+id/login_frame_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#id/email_frame_layout"
android:layout_alignLeft="#id/email_frame_layout"
android:layout_alignEnd="#id/email_frame_layout"
android:layout_alignRight="#id/email_frame_layout"
android:layout_below="#id/password_frame_layout">
<Button
android:id="#+id/Sign_in_button"
style="#style/main_button"
android:layout_width="match_parent"
android:layout_height="#dimen/signin_edittext_height"
android:text="#string/signin_text_button"
android:textColor="#color/login_button_text"
android:onClick="startplay"/>
<ProgressBar
android:id="#+id/sign_in_loading_spinner"
android:layout_width="wrap_content"
android:layout_height="30dp"
style="#android:style/Widget.ProgressBar"
android:layout_gravity="center_vertical|end"
android:visibility="gone"/>
</FrameLayout>
</RelativeLayout>
and this is EditText Custom view
public class EditTextPushContent extends EditText{
private static int anchorId;
public EditTextPushContent(Context context, AttributeSet attrs) {
super(context, attrs);
if (attrs == null) {
throw new IllegalArgumentException();
}
TypedArray typedArray = context.obtainStyledAttributes(attrs,
R.styleable.EditTextPushContent);
final int anchorIdEditText =
typedArray.getResourceId(R.styleable.EditTextPushContent_anchorId, -1);
typedArray.recycle();
if (anchorIdEditText == -1) {
throw new IllegalArgumentException();
}
final View mainView = ((Activity)
context).getWindow().getDecorView().findViewById(android.R.id.content);
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new
ViewTreeObserver.OnGlobalLayoutListener() {
public void onGlobalLayout() {
Rect rectMainView = new Rect();
mainView.getWindowVisibleDisplayFrame(rectMainView);
int heightDiff = mainView.getRootView().getHeight() -
(rectMainView.bottom - rectMainView.top);
if (heightDiff > 100) {
View anchorView = mainView.findViewById(anchorId);
if (anchorView != null) {
int[] location = new int[2];
anchorView.getLocationOnScreen(location);
int anchorY = location[1];
EditTextPushContent.this.getLocationOnScreen(location);
int translation = (anchorY + anchorView.getHeight()) -
location[1];
if (translation > 5) {
mainView.animate().translationY(-(translation));
}
}
}
else {
mainView.animate().translationY(0);
}
}
});
this.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
EditTextPushContent.anchorId = anchorIdEditText;
mainView.getViewTreeObserver().dispatchOnGlobalLayout();
}
});
}
}
and this is styles.xml it will be used by custom view class
<resources>
<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar">
</style>
<style name="main_button">
<item name="android:textColor">#ECEFF1</item>
<item name="android:textSize">#dimen/button_text_height_medium</item>
<item name="android:fontFamily">sens-serif</item>
<item name="android:background">#drawable/login_btn_selector</item>
</style>
<style name="login_edittext">
<item name="android:textSize">18sp</item>
<item name="android:background">#316BAF</item>
<item name="android:paddingLeft">5sp</item>
</style>
</resources>
when i run this application on android device and crashed unexpectedly
i want to clarify one thing that when this application executed with default Edit Text It runs Properly but crashes if custom view used in activity.
if seems that the custom view is not properly configured .Please Help!!!!
Rendering Problems
The following classes could not be instantiated:
- com.example.hp.newapplication.EditTextPushContent (Open Class, Show Exception, Clear Cache)
Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE Exception Details java.lang.ClassCastException: com.android.layoutlib.bridge.android.BridgeContext cannot be cast to com.example.hp.newapplication.NewActivity   at com.example.hp.newapplication.EditTextPushContent.(EditTextPushContent.java:31)   at java.lang.reflect.Constructor.newInstance(Constructor.java:526)   at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:835)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)   at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:838)   at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)   at android.view.LayoutInflater.rInflate(LayoutInflater.java:811)   at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)   at android.view.LayoutInflater.inflate(LayoutInflater.java:515)   at android.view.LayoutInflater.inflate(LayoutInflater.java:394)

Related Links

An alternative to Android's webview
Filling ExpendableListView with database entries
Rows not refreshing when calling Custom SimpleCursorAdapter
Using Android MapView without the MapActivity?
Debugging Dalvik VM
Parsing with XmlPullParser from SDcard
Drag Image on Touch
Why do you need the following sequence in String manipulation in Android,
Android click event of items in HorizontalScrollView not respond after scroll
How can set the height of two layouts.?
how to know HTTP Post upload complete while using HttpResponse in android
JTransforms FFT in Android from PCM data
Getting METADATA of currently played audio in Android
Android liner layout align center and right
Does the Android GPS drain battery when trying to get first fix?
Is there a way to set an MP3 file as a ringtone on Android using Adobe AIR?

Categories

HOME
android
windows
fabricjs
oracle12c
scikit-learn
linkedin
rdbms
zend-framework
saml-2.0
jsf-2.2
aws-cli
telegram-bot
maxscript
google-cloud-datalab
gluon-mobile
extjs4.2
32bit-64bit
categorical-data
github-enterprise
resultset
mxgraph
datastage
jsonpath
symmetricds
modbus-tcp
powershell-v5.0
html5-appcache
jersey-1.0
pyramid
gulp-watch
angular-routing
visual-studio-extensions
joptionpane
bulletphysics
alm
paragraph
sql-delete
mnist
playframework-2.1
zoomify
git-rewrite-history
unordered-map
setup.py
ovf
lampp
identification
datamaps
insight
stdmap
semantic-logging
modelsim
rackspace-cloud
offline.js
rxtx
sandcastle
vcloud-director-rest-api
taocp
slackware
pytables
dotnetnuke-7
nikeplus-api
expectations
vorpal.js
query-by-example
uiactionsheet
fink
np-spring
kendo-upload
contentcontrol
crouton-os
directdraw
concurrentmodification
themoviedb-api
vigenere
jdi
xvim
cgi-bin
eoferror
atoi
linked-tables
canvg
typeconverter
ms-access-2000
kubuntu
jquery-forms-plugin
structuremap3
mdichild
alternate
solace-mq
ebay-lms
cocoalibspotify-2.0
inappsettingskit
tlf
asdf
pclzip
onload-event
device-width
dopostback
android-loadermanager
fitbounds
luabind
htdocs
listactivity
opml

Resources

Encrypt Message