Android: stop scrolling when imageview is touched? - java

I try to make it possible to rotate an ImageView, but the scrolling gets in my way. How can I stop the scrolling while the ImageView is touched? I don't think that code is necessary, but here is goes:
fragment_main.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivityFragment"
android:background="#drawable/texture">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Πάγωσε η κόλαση..."
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_0"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:paddingTop="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Μπρρρ!"
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Κρύο"
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="75dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Έτσι κ'έτσι..."
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_3"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Καλό"
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="125dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Πολύ καλό!"
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_5"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="150dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Κάνεις κοιλιακούς!"
android:textColor="#color/label_color"
android:textSize="20dp"
android:id="#+id/label_6"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="175dp" />
<ImageView
android:src="#drawable/thermostat"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thermostat"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/margin" />
<ImageView
android:src="#drawable/thermostat_slider"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/thermostat_slider"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/margin" />
<ImageView
android:src="#drawable/inside_thing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/inside_thing"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/margin" />
<ImageView
android:src="#drawable/inside_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/inside_text"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/margin" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Τι κάνω?"
android:textColor="#color/label_color"
android:textStyle="bold"
android:id="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="#dimen/title_margin"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/text"
android:text="#string/help_text"
android:textColor="#color/label_color"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="750dp" />
</RelativeLayout>
</ScrollView>

You cannot disable the scrolling of a ScrollView. You would need to extend to ScrollView and override the onTouchEvent method to return false when some condition is matched.
public class LockableScrollView extends ScrollView {
private boolean mScrollable=true;
public LockableScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
}
Override required methods and constructors
#Override
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (mScrollable) return super.onTouchEvent(ev); //return mScrollable condition is false
/*
*Write your code here to implement your functionality like if you image view is touched
*/
// only continue to handle the touch event if scrolling enabled
return mScrollable; // mScrollable is always false at this point
// mScrollable flag may help you
//use it as a condition
default:
return super.onTouchEvent(ev);
}
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// if we can scroll pass the event to the superclass
if (mScrollable) return super.onInterceptTouchEvent(ev);
// only continue to handle the touch event if scrolling enabled
return mScrollable; // mScrollable is always false at this point
default:
return super.onInterceptTouchEvent(ev);
}
}

Related

How to fix ViewPager to prevent app to getting error and crash?

i'm working on login page, based on Androidhive tutorial and problem is Viewpager work fine with 2 layout but for 3 layouts app gonna crash.
In androidhive tutorial used 2 layout but i want to use 3 because i'm getting sms then otp then register, so problem is with 3rd layout which it won't appear and crash.
Androidhive Tutorial Link:
Part 1 Part 2
Here are the codes :
XML
<LinearLayout
android:id="#+id/layout_phone_registration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="25dp"
android:layout_marginTop="100dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center_horizontal"
android:inputType="textCapWords"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:text="#string/msg_enter_mobile"
android:textColor="#android:color/white"
android:textSize="14dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/inputMobile"
android:layout_width="240dp"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:fontFamily="sans-serif-light"
android:hint="#string/lbl_mobile"
android:inputType="phone"
android:maxLength="12"
android:padding="5dp"
android:textColor="#color/colorPrimary"
android:textCursorDrawable="#null"
android:textSize="18dp" />
<Button
android:id="#+id/btn_request_sms"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:background="#color/colorPrimaryDark"
android:text="#string/lbl_next"
android:textColor="#android:color/white"
android:textSize="14dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/layout_otp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="25dp"
android:layout_marginTop="100dp"
android:src="#mipmap/ic_launcher" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:gravity="center_horizontal"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:text="#string/msg_sit_back"
android:textColor="#android:color/white"
android:textSize="16dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:gravity="center_horizontal"
android:paddingLeft="40dp"
android:paddingRight="40dp"
android:text="#string/msg_manual_otp"
android:textColor="#android:color/white"
android:textSize="12dp" />
<EditText
android:id="#+id/inputOtp"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:fontFamily="sans-serif-light"
android:gravity="center_horizontal"
android:hint="#string/lbl_enter_otp"
android:inputType="number"
android:maxLength="6"
android:padding="10dp"
android:textCursorDrawable="#null"
android:textSize="18dp" />
<Button
android:id="#+id/btn_verify_otp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:background="#color/colorPrimaryDark"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:text="#string/lbl_submit"
android:textColor="#android:color/white"
android:textSize="14dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/layout_complete_registration"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/colorPrimary"
android:gravity="center_horizontal"
android:orientation="vertical">
<EditText
android:id="#+id/inputName"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="#android:color/white"
android:fontFamily="sans-serif-light"
android:hint="#string/lbl_name"
android:padding="5dp"
android:singleLine="true"
android:textColor="#color/colorPrimary"
android:textSize="18dp" />
<EditText
android:id="#+id/inputAddress"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:background="#android:color/white"
android:fontFamily="sans-serif-light"
android:hint="#string/lbl_email"
android:padding="5dp"
android:textColor="#color/colorPrimary"
android:textSize="18dp" />
<Button
android:id="#+id/btn_register_user"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="25dp"
android:background="#color/colorPrimaryDark"
android:text="#string/lbl_next"
android:textColor="#android:color/white"
android:textSize="14dp" />
</LinearLayout>
</ir.atlaspio.atlasdrinkingservice.AdvancedUI.MyViewPager>>
<ProgressBar
android:id="#+id/progressBar"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginBottom="60dp"
android:indeterminateTint="#color/colorAccent"
android:indeterminateTintMode="src_atop"
android:visibility="gone" />
<LinearLayout
android:id="#+id/layout_edit_mobile"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="50dp"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txt_edit_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:textSize="16dp" />
<ImageButton
android:id="#+id/btn_edit_mobile"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:background="#null"
android:src="#drawable/ic_exit_to_app_black_24dp" />
</LinearLayout>
Java
private ViewPager viewPager;
private ViewPagerAdapter adapter;
OnCreate =>
viewPager.setCurrentItem(0);
adapter = new ViewPagerAdapter();
viewPager.setAdapter(adapter);
viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
#Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
#Override
public void onPageSelected(int position) {
}
#Override
public void onPageScrollStateChanged(int state) {
}
});
Public Class Activity =>
class ViewPagerAdapter extends PagerAdapter {
#Override
public int getCount() {
return 3;
}
#Override
public boolean isViewFromObject(View view, Object object) {
return view == ((View) object);
}
public Object instantiateItem(View collection, int position) {
int resId = 0;
switch (position) {
case 0:
resId = R.id.layout_phone_registration;
break;
case 1:
resId = R.id.layout_otp;
break;
case 2:
resId = R.id.layout_complete_registration;
break;
}
return findViewById(resId);
}
}
Logcat
08-29 10:48:12.426 4499-4499/ir.atlaspio.atlasdrinkingservice
E/InputEventSender: Exception dispatching finished signal.
08-29 10:48:12.426 4499-4499/ir.atlaspio.atlasdrinkingservice E/MessageQueue-JNI: Exception in MessageQueue callback:
handleReceiveCallback
08-29 10:48:12.436 4499-4499/ir.atlaspio.atlasdrinkingservice E/MessageQueue-JNI: java.lang.UnsupportedOperationException: Required
method destroyItem was not overridden
at android.support.v4.view.PagerAdapter.destroyItem(PagerAdapter.java:201)
at android.support.v4.view.PagerAdapter.destroyItem(PagerAdapter.java:128)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1172)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:663)
at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:625)
at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:617)
at android.support.v4.view.ViewPager.pageRight(ViewPager.java:2888)
at android.support.v4.view.ViewPager.arrowScroll(ViewPager.java:2844)
at android.support.v4.view.ViewPager.executeKeyEvent(ViewPager.java:2764)
at android.support.v4.view.ViewPager.dispatchKeyEvent(ViewPager.java:2738)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
at android.support.v7.app.AppCompatActivity.dispatchKeyEvent(AppCompatActivity.java:534)
at android.support.v7.view.WindowCallbackWrapper.dispatchKeyEvent(WindowCallbackWrapper.java:58)
at android.support.v7.app.AppCompatDelegateImplBase$AppCompatWindowCallbackBase.dispatchKeyEvent(AppCompatDelegateImplBase.java:316)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3876)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3850)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3549)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3606)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3582)
at android.view.ViewRootImpl$ImeInputStage.onFinishedInputEvent(ViewRootImpl.java:3742)
at android.view.inputmethod.InputMethodManager$PendingEvent.run(InputMethodManager.java:2010)
at android.view.inputmethod.InputMethodManager.invokeFinishedInputEventCallback(InputMethodManager.java:1704)
at android.view.inputmethod.InputMethodManager.finishedInputEvent(InputMethodManager.java:1695)
at android.view.inputmethod.InputMethodManager$ImeInputEventSender.onInputEventFinished(InputMethodManager.java:1987)
at android.view.InputEventSender.dispatchInputEventFinished(InputEventSender.java:141)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:5019)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.
As per your error
java.lang.UnsupportedOperationException: Required method destroyItem was not overridden
You need to add this method in your pager adapter
#Override
void destroyItem (ViewGroup container, int position, Object object){
((ViewPager) container).removeView((View) object);
// more code if needed
}
Override destroyItem method in your ViewPagerAdapter class and remove obj as container.removeView(obj as LinearLayout) where LinearLayout is your root layout
#Override
void destroyItem(ViewGroup container, int position, Object obj) {
container.removeView(obj as LinearLayout)
}

How can I focus on a Button within a custom ListView

In my app it has a custom ListView'. The ListView contains an Image button. At the moment if the user is using an Android phone or tablet they can select and press this Button.
But if they are using for example a Firestick that uses a remote I can't select it. How can I make sure that I can scroll through my list but also make sure it scrolls through the buttons as well when using a remote?
My custom.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/titleapp"
android:textSize="20dp"
android:textColor="#drawable/button_textcolour"
android:layout_marginLeft="6dp"
android:layout_marginRight="6dp"
android:layout_marginTop="12dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/img" />
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/detail"
android:layout_margin="6dp"
android:textSize="15dp"
android:layout_below="#+id/titleapp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/img"
android:layout_toEndOf="#+id/img"
android:textColor="#drawable/button_textcolour"/>
<ImageView
android:layout_width="45dp"
android:padding="5dp"
android:id="#+id/img"
android:scaleType="fitCenter"
android:cropToPadding="true"
android:adjustViewBounds="true"
android:layout_height="45dp"
android:layout_alignBottom="#+id/detail"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/downloads"
android:id="#+id/downloadcounttext"
android:layout_below="#+id/detail"
android:layout_alignEnd="#+id/detail"
android:layout_marginRight="50dp"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"
android:layout_marginLeft="5dp"
android:id="#+id/counterdl"
android:layout_below="#+id/detail"
android:layout_alignEnd="#+id/detail"
android:layout_marginEnd="37dp"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/date_added"
android:id="#+id/dateaddedtxt"
android:layout_below="#+id/detail"
android:layout_alignStart="#+id/detail"
android:textColor="#drawable/button_textcolour"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="01/01/0000"
android:id="#+id/datetext"
android:layout_below="#+id/detail"
android:layout_toEndOf="#+id/dateaddedtxt"
android:textColor="#drawable/button_textcolour"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report?"
android:paddingRight="5dp"
android:layout_alignTop="#+id/img"
android:layout_toStartOf="#+id/report"
android:layout_alignParentTop="true"
android:layout_margin="5dp" />
//HERE I WANT THIS BUTTON ON EVERY ITEM TO BE ABLE TO GAIN FOCUS WITH IN THE LIST
<ImageButton
android:layout_margin="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/report"
android:background="#drawable/ic_sentiment_dissatisfied_black_24dp"
android:layout_alignEnd="#+id/detail" />
My method in my BaseAdapter that allows selection of the button:
public View getView(final int position, View convertView, ViewGroup parent) { final View row;
if (convertView == null) {
row = LayoutInflater.from(parent.getContext()).inflate(R.layout.custom, parent, false);
} else {
row = convertView;
}
report = row.findViewById(R.id.report);
report.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
title.setText(Title[position]);
String getappname = title.getText().toString();
if (getappname!= null){
Log.i("Bad App ", getappname);

Hide and show when check box is checked

In my Activity A , I have checkbox, spinner and editText. If checkbox is checked, it will show editText and hide spinner and textView .Otherwise, it will show them.
public void addListenerOnChk() // for checkbox
{
checkBox2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(((CheckBox)v).isChecked())
{
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else
{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
}
});
So this is my layout
Before checkbox is checked
After
If the checkbox did not checked, how can I move the progress bar below the checkbox(Currently it has a space for editText)?
If checkbox checked, how to move up the checkbox and hide the spinner and text ? Thanks.
Here my layout...sorry, it a bit long (but the things I want to change is id/ProjectName, id/checkbox2 and id/editText). id/checkbox2 and id/editText is in the last two paragraph.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout"
android:background="#mipmap/background_work_details">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ProjectName"
android:padding="10dp"
android:text="Project/Service/Training"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="11dp" />
<Spinner
android:layout_width="322dp"
android:layout_height="41dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="15dp"
android:layout_y="47dp"
android:id="#+id/SpinnerProject"
android:spinnerMode="dropdown" />
<EditText
android:layout_width="339dp"
android:layout_height="156dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:paddingBottom="80dp"
android:layout_x="14dp"
android:layout_y="730dp"
android:id="#+id/editTextWorkDescription" />
<SeekBar
android:layout_width="206dp"
android:layout_height="wrap_content"
android:id="#+id/seekBarPercentage"
android:layout_x="30dp"
android:layout_y="189dp"
android:indeterminate="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:padding="10dp"
android:text="Time In"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="16dp"
android:layout_y="225dp" />
<EditText
android:layout_width="80dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:focusableInTouchMode="false"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="86dp"
android:layout_y="225dp"
android:id="#+id/TimeIn" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:padding="10dp"
android:text="Time Out"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="172dp"
android:layout_y="225dp" />
<EditText
android:layout_width="87dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:focusableInTouchMode="false"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="246dp"
android:layout_y="225dp"
android:id="#+id/TimeOut" />
<Button
android:layout_width="127dp"
android:layout_height="63dp"
android:text="save"
android:drawableRight="#mipmap/save"
android:id="#+id/save"
android:layout_x="217dp"
android:layout_y="891dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textProgress"
android:layout_x="257dp"
android:textColor="#color/red"
android:layout_y="194dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView7"
android:padding="10dp"
android:text="Travel From"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="262dp" />
<EditText
android:layout_width="223dp"
android:layout_height="85dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="14dp"
android:layout_y="300dp"
android:id="#+id/travelFrom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView15"
android:padding="10dp"
android:text="Travel To"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="390dp" />
<EditText
android:layout_width="97dp"
android:layout_height="35dp"
android:layout_margin="10dp"
android:inputType="numberDecimal"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="15dp"
android:layout_x="255dp"
android:layout_y="470dp"
android:id="#+id/mileage" />
<EditText
android:layout_width="222dp"
android:layout_height="85dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="14dp"
android:layout_y="423dp"
android:id="#+id/travelTo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView16"
android:padding="10dp"
android:inputType="numberDecimal"
android:text="Hotel accomm"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="550dp"
android:allowUndo="true" />
<EditText
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:inputType="numberDecimal"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:paddingLeft="15dp"
android:layout_x="131dp"
android:layout_y="554dp"
android:id="#+id/hotel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView17"
android:padding="10dp"
android:text="Toll"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="222dp"
android:layout_y="550dp" />
<EditText
android:layout_width="187dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:inputType="numberDecimal"
android:paddingLeft="15dp"
android:layout_x="163dp"
android:layout_y="620dp"
android:id="#+id/business" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView18"
android:padding="10dp"
android:text="Business Expenses"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="620dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView19"
android:padding="10dp"
android:text="Mileage"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="268dp"
android:layout_y="430dp" />
<EditText
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:inputType="numberDecimal"
android:paddingLeft="15dp"
android:layout_x="263dp"
android:layout_y="554dp"
android:id="#+id/toll" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView20"
android:padding="10dp"
android:text="Work Description"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="683dp" />
<CheckBox
android:layout_width="112dp"
android:layout_height="53dp"
android:text="outstation"
android:id="#+id/checkBox"
android:textColor="#color/peru"
android:layout_x="232dp"
android:layout_y="662dp"
android:checked="false" />
<CheckBox
android:layout_width="112dp"
android:layout_height="45dp"
android:text="Others?"
android:id="#+id/checkBox2"
android:layout_x="24dp"
android:textColor="#color/peru"
android:layout_y="92dp"
android:checked="false" />
<EditText
android:layout_width="296dp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:visibility="gone"
android:layout_x="27dp"
android:layout_y="133dp" />
</AbsoluteLayout>
</ScrollView>
Your problem is because you are using absolute_layout with layout_x and layout_y, so all views will be at your predefined positions of x and y, no matter what elements will you remove or what elements will you leave.
So, you have to change the layout parameters for the elements not just set it's visibility to VISIBLE or GONE, so the complete solution will be:
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
// now settings the new parameters
AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) typeProject.getLayoutParams());
params.x = 100; // the new value
params.y = 100; // the new value
typeProject.setLayoutParams(params);
}
else{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
// use the same way here with 'project' and 'ProjectName'
}
});
Try with OnCheckedChangeListener:
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
});
You should use OnCheckedChangeListener, rather than OnClickListener
Do this
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked)
{
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else
{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
}
});

Android: How to find which tab is active in a tablayout?

I am currently working on a simple android application.
There is a login page, and as it is possible to login as a Driver or as a Passenger, there are different tabs in that page.
I have to use the same "email" and "password fields a, and the same login button. basically the only thing that change is the subtitle
I need to figure out which tab is active when the login button is pressed, in order to use the right login options and send the user to the right place.
Here are parts of the code:
Login layout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.domain.myname.schoolproject.Login_Screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/Nom_Application"
android:id="#+id/txtTitle"
android:textAlignment="center"
android:textColor="#010101"
android:textSize="45sp"
android:textStyle="bold"
android:autoText="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Connexion"
android:id="#+id/txtSubtitle"
android:layout_marginTop="20dp"
android:textColor="#010101"
android:textSize="18sp"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_below="#+id/txtTitle"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/imgLeft"
android:src="#drawable/carleft"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="70dp"
android:contentDescription="#string/Description_icône" />
<ImageView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:id="#+id/imgRight"
android:src="#drawable/carright"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignBottom="#+id/imgLeft"
android:contentDescription="#string/Description_icône"
android:layout_alignParentStart="false" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_below="#+id/imgLeft" />
<android.support.design.widget.TabLayout
android:id="#+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:layout_alignTop="#+id/toolbar" />
<android.support.v4.view.ViewPager
android:id="#+id/pager"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_weight="1"
android:background="#android:color/white"
android:layout_below="#+id/sliding_tabs"
android:layout_alignBottom="#+id/edtPassword" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/edtMail"
android:hint="#string/Mail"
android:textSize="20dp"
android:textIsSelectable="true"
android:layout_alignLeft="#+id/edtPassword"
android:layout_alignStart="#+id/edtPassword"
android:layout_marginTop="20dp"
android:layout_above="#+id/edtPassword" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/edtPassword"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:elegantTextHeight="false"
android:hint="#string/Password"
android:textSize="20dp"
android:textIsSelectable="false"
android:layout_above="#+id/btnConnexion"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/Inscription"
android:id="#+id/btnInscription"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp"
android:background="#0006ff"
android:textColor="#ffffff"
android:textSize="20dp"
android:layout_alignParentEnd="true"
android:onClick="onInscription" />
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/title_activity_login_screen"
android:id="#+id/btnConnexion"
android:background="#15c100"
android:textSize="20dp"
android:layout_above="#+id/btnInscription"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp"
android:textColor="#ffffff"
android:onClick="onConnexion"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/txtError"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:textColor="#d60c00"
android:singleLine="false" />
</RelativeLayout>
One of the fragment layouts
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.domain.myname.schoolproject.Login_Screen">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/Driver"
android:id="#+id/txtSubtitle"
android:textColor="#010101"
android:textSize="18sp"
android:textIsSelectable="false"
android:textStyle="bold"
android:layout_centerHorizontal="true" />
</RelativeLayout>
The pageAdapter class
public class PageAdapter extends FragmentPagerAdapter {
private Context context;
public PageAdapter(FragmentManager fm, Context context) {
super(fm);
this.context=context;
}
public Fragment getItem(int pos) {
switch (pos) {
case 0:
return new LoginDriver();
case 1:
return new LoginPassenger();
}
return null;
}
public int getCount() {
return 2;
}
public CharSequence getPageTitle(int pos) {
switch (pos) {
case 0:
return context.getApplicationContext().getResources().getString(R.string.Driver);
case 1:
return context.getApplicationContext().getResources().getString(R.string.Passenger);
}
return null;
}
}
And from the LoginScreen class, I need to find out the current tab in this event
public void onConnexion(View view) {
android.content.Intent getNextScreen;
String mail = txtMail.getText().toString();
String pass = txtPass.getText().toString();
//Identification(this.)
getNextScreen = new android.content.Intent(this, Summary_Driver_Screen.class);
startActivity(getNextScreen);
}
Thank you very much for your help. I can give more details if needed.
getSelectedTabPosition() does exactly what you need: returning the current index of the selected tab.

ListView row not clickable (after adding two buttons)

Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView

Categories

Resources