TextView Edit Text is not responding to Click Events - android

I have a layout with three TextViews, two TextViews are responding to Click Events but the last one is not responding. I am using Navigation to navigate to other fragments. The OnClick method is called inside an adapter which implements view.OnClickListener.
XML
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_marginStart="#dimen/defaultMargin"
android:layout_height="wrap_content">
<TextView
android:text="How CADO works"
style="#style/CircularBook"
android:drawableEnd="#drawable/arrow_right"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/howCadoWorks"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="#id/howCadoWorks"
android:layout_width="match_parent"
android:background="#color/pinkishGray"
android:layout_height="0.5dp"
android:id="#+id/view3"></View>
<TextView
android:text="FAQ"
style="#style/CircularBook"
android:layout_width="0dp"
android:drawableEnd="#drawable/arrow_right"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/faqs"
app:layout_constraintTop_toBottomOf="#+id/view3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<View
app:layout_constraintTop_toBottomOf="#id/faqs"
android:layout_width="match_parent"
android:background="#color/pinkishGray"
android:layout_height="0.5dp"
android:id="#+id/view4"></View>
<TextView
android:text="Contact Us"
android:drawableEnd="#drawable/arrow_right"
style="#style/CircularBook"
android:layout_width="0dp"
android:layout_height="#dimen/buttonHeight"
android:id="#+id/contactus"
app:layout_constraintTop_toBottomOf="#+id/view4"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
OnClickMethod
public void onClick(#Nullable View view) {
NavController var3 = Navigation.findNavController(view);
if(view.getId()==R.id.contactus){
**var3.navigate(R.id.contactus_fragment);**
return;
}
else if (view.getId()==R.id.faqs){
var3.navigate(R.id.faqFragmnt);
return;
}
else if (view.getId()==R.id.howCadoWorks){
Toast.makeText(view.getContext(),"Feature is in Progress", Toast.LENGTH_SHORT).show();
// var3.navigate(R.id.contactus_fragment);
return;
}
else
{
}
}
I have tried multiple ways, rechecked id's as well but nothing is working.

as #Nilesh Rathod said, you need to make sure that all your text view have set an on click listener like:
textView.setOnClickListener(this);
or you can also:
textView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
// Here you put the code you want to use for the specific textView click event
}
});

Related

How we can create radio button with image and selected true button

Kindly let me know How we can create radio button with image and selected true button?
Here I have attached the screen shot that what i need?
I made three custom radio button using textview you can use imageview
this is my xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:orientation="vertical">
<TextView
android:id="#+id/tv_home"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:text="#string/home"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
app:drawableTopCompat="#drawable/ic_home"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/tv_jpg"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" />
<TextView
android:id="#+id/tv_jpg"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:text="#string/files"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
app:drawableTopCompat="#drawable/ic_files"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="#+id/tv_pdf"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/tv_home" />
<TextView
android:id="#+id/tv_pdf"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackgroundBorderless"
android:gravity="center"
android:paddingTop="#dimen/docs__bottom_icon_padding"
android:paddingBottom="#dimen/docs__bottom_icon_padding"
android:drawablePadding="#dimen/padding_icon_text_top_bar_docs"
android:text="#string/pdf"
app:drawableTopCompat="#drawable/ic_pdf"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="#+id/tv_jpg" />
</androidx.constraintlayout.widget.ConstraintLayout>
in onCreate of activity write this code
tv_home.setOnClickListener {
setSelected(tv_home)
}
tv_jpg.setOnClickListener {
setSelected(tv_jpg)
}
tv_pdf.setOnClickListener {
setSelected(tv_pdf)
}
and outer side of oncreate make a method as
private fun setSelected(pTextViw: TextView) {
if (tv_home == pTextViw) {
tv_home.compoundDrawables[1].setTint(mSelectedColor)
tv_home.setTextColor(mSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mUnSelectedColor)
tv_jpg.setTextColor(mUnSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mUnSelectedColor)
tv_pdf.setTextColor(mUnSelectedColor)
} else if (tv_jpg == pTextViw) {
tv_home.compoundDrawables[1].setTint(mUnSelectedColor)
tv_home.setTextColor(mUnSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mSelectedColor)
tv_jpg.setTextColor(mSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mUnSelectedColor)
tv_pdf.setTextColor(mUnSelectedColor)
} else if (tv_pdf == pTextViw) {
tv_home.compoundDrawables[1].setTint(mUnSelectedColor)
tv_home.setTextColor(mUnSelectedColor)
tv_jpg.compoundDrawables[1].setTint(mUnSelectedColor)
tv_jpg.setTextColor(mUnSelectedColor)
tv_pdf.compoundDrawables[1].setTint(mSelectedColor)
tv_pdf.setTextColor(mSelectedColor)
}
}

ButterKnife #onClick method for Button view is not working

I was updating an existing code by introducing dismiss button, and the onClick Butterknife method is not working for dismiss button, whereas its working for close button. In the below code, I am enabling the close button for some devices and for other devices I am enabling the dismiss button. I am quite unsure why this "dismiss" button is not working, whereas the close button is working fine. And both of them use the ButterKnife, onClick method - onSkip()
InfoActivity.java :
public class InfoActivity extends BccActiviy {
#BindView(R.id.ImageView_CloseView)
ImageView tCloseView;
#BindView(R.id.Dismiss)
Button tDismiss;
.....
#OnClick({R.id.Dismiss, R.id.ImageView_CloseView})
public void onSkip(View v) {
onDissmissPressed();
}
public void initialize(Bundle savedInstanceState) {
if (tConfig.isDismiss()) {
tCloseView.setVisibility(View.GONE);
tDismiss.setVisibility(View.VISIBLE);
} else {
tDismiss.setVisibility(View.GONE);
}
}
}
info_screen.xml :
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:ignore="All"
android:id="#+id/root_layout"
android:background="#color/fd_theme"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/ImageView_CloseView"
style="#style/CancelButton"
android:layout_width="#di/target_size"
android:layout_marginTop="#di/p_6"
android:layout_height="#di/target_size"
android:layout_alignParentStart="true"
android:clickable="true"
android:contentDescription="#string/close_btn_txt"
android:importantForAccessibility="yes"
android:paddingStart="#di/p_14"
android:paddingEnd="#di/p_14"
android:background="?attr/bg_color"
app:srcCompat="#drawable/icn_close_white"/>
<LinearLayout
android:id="#+id/TextView_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="vertical">
<TextView
android:id="#+id/TextContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="#di/size_2x"
android:focusableInTouchMode="true"
android:gravity="center"
android:text="#string/text"
android:textColor="#color/white"
android:textSize="#di/rating"
android:textAlignment="center"/>
<com.package.button.star.views.widgets.StaView
android:id="#+id/StarView_AppRating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center">
</com.package.button.star.views.widgets.StarView>
<Button
android:id="#+id/Dismiss"
style="#style/buttonStyle"
android:layout_marginTop="#di/margin_top"
android:paddingLeft="#di/padding_50"
android:paddingTop="#di/padding_18"
android:paddingRight="#di/padding_50"
android:paddingBottom="#di/padding_18"
android:text="Dismiss"
android:onClick="onSkip"
android:textAlignment="center"
android:textAllCaps="false"
android:textSize="#di/dismiss_fontSize"
android:visibility="visible"
android:focusable="true"
tools:text="Dismiss" />
<ViewStub
android:id="#+id/actions_stub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="#di/margin_center"
android:inflatedId="#+id/view_actions"
android:layout="#layout/view_actions" />
</LinearLayout>
</FrameLayout>
Try removing the onClick from xml.

Changing a Item in a listView on a click

I want to make a ListView, when you long click on an item, the item will be added to the buttons: delete and update (only the clicked item):
So I have made a ListView in my MainLayout:
<ListView
android:id="#+id/neighborhood"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="#+id/allAddresses"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/AddresSearch" />
and a Custom ListView Item lay out, which contains 3 TextViews:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/button_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".passItemView">
<TextView
android:id="#+id/num"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="28dp"
android:text="cv"
app:layout_constraintEnd_toStartOf="#+id/house"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/house"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:text="cvc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/pass"
android:layout_width="86dp"
android:layout_height="45dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="32dp"
android:text="cv"
app:layout_constraintEnd_toStartOf="#+id/num"
app:layout_constraintTop_toTopOf="parent" />
and this layout is conneted to a class "passItemView", and there, what I did is that on longClick on the layout it will add 2 button (or even just will make a toast)
But it does nothing.
public class passItemView extends AppCompatActivity {
Button delete = new Button(this);
Button update = new Button(this);
ConstraintLayout btnLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pass_item_view);
btnLayout = (ConstraintLayout) findViewById(R.id.button_layout);
btnLayout.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
Toast.makeText(passItemView.this,"Toast it",Toast.LENGTH_LONG).show();
btnLayout.addView((delete));
btnLayout.addView((update));
return false;
}
});
Thank you for your Help.
use an boolean value (ex : showButtons) and initialize set it false for all items.
when you clicked someitem make items showButtons variable true and notifydatasetchange (reload lsitview) again.

Animate LayoutChanges does not work properly

I want to animate text in my textswitcher. I went through all the stack questions and the documentation, but they didn't solve my problem.
Here is my XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/tv__inc_pre_sing__screen_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#fff"
android:gravity="center"
android:text="PRACTICE"
android:textAllCaps="true"
android:textColor="#color/colorAccent"
android:textSize="16dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/rl__inc_pre_sing__tm_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#efff"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__screen_title">
<ImageView
android:id="#+id/tv__inc_pre_sing__quotation_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:src="#drawable/ic_archive_black_24dp"
app:layout_constraintTop_toTopOf="parent" />
<TextSwitcher
android:id="#+id/tv__inc_pre_sing__teacher_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="#id/tv__inc_pre_sing__quotation_mark"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
android:src="#drawable/ic_archive_black_24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/tv__inc_pre_sing__teacher_message" />
</android.support.constraint.ConstraintLayout>
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Click Me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<View
android:layout_width="0dp"
android:layout_height="16dp"
android:background="#drawable/ic_launcher_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#id/rl__inc_pre_sing__tm_container" />
</android.support.constraint.ConstraintLayout>
Here is my code
public class Main3Activity extends AppCompatActivity {
private TextSwitcher mSwitcher;
Button btnNext;
int currentIndex=-1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
Resources resources = getApplicationContext().getResources();
final String[] textString = resources.getStringArray(R.array.teacher_messages);
btnNext = findViewById(R.id.button);
mSwitcher = findViewById(R.id.tv__inc_pre_sing__teacher_message);
mSwitcher.setFactory(new ViewSwitcher.ViewFactory() {
public View makeView() {
// TODO Auto-generated method stub
// create new textView and set the properties like clolr, size etc
TextView myText = new TextView(Main3Activity.this);
myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
myText.setTextColor(Color.BLUE);
return myText;
}
});
// Declare the in and out animations and initialize them
Animation in = AnimationUtils.loadAnimation(this,android.R.anim.slide_in_left);
Animation out = AnimationUtils.loadAnimation(this,android.R.anim.slide_out_right);
// set the animation type of textSwitcher
mSwitcher.setInAnimation(in);
mSwitcher.setOutAnimation(out);
// ClickListener for NEXT button
// When clicked on Button TextSwitcher will switch between texts
// The current Text will go OUT and next text will come in with specified animation
btnNext.setOnClickListener(new View.OnClickListener() {
//
public void onClick(View v) {
// TODO Auto-generated method stub
currentIndex++;
// If index reaches maximum reset it
if(currentIndex==textString.length)
currentIndex=0;
mSwitcher.setText(textString[currentIndex]);
((ViewGroup) findViewById(R.id.rl__inc_pre_sing__tm_container)).getLayoutTransition()
.enableTransitionType(LayoutTransition.CHANGING);
}
});
}
}
The animation on ConstraintLayout whose id is rl__inc_pre_sing__tm_container does not work properly. Suppose my TextSwitcher has text whose length is greater than 3 and then TextSwitcher shows text whose length is 1 then the ConstraintLayout does not animate, if the next text is of length 1 then the constraintlayout animates.
I am not able to figure out this weird behaviour.
Here is the issue: When the TextSwitcher transitions from X lines of text to something less than X lines then the TextSwitcher's height does not change.
The TextSwitcher inherits some behavior from ViewAnimator which considers the height of all views when determining the height of the widget. The solution is to add the following XML to the TextSwitcher definition in the layout file that will inhibit this behavior:
android:measureAllChildren="false"
Thanks to this Stack Overflow answer that states all this better than I have.

Cannot Click List Item in HorizontalScrollView

I'm noticing that by adding the HorizontalScrollView it's disabling my ability to select items on my ListView. This seems like a pretty basic/common feature to want to add (I want to be able to swipe my item to the left to offer a delete option) but HorizontalScrollView appears to be incompatible with items that you would like to also touch to select. Note that if I change HorizontalScrollView to a LinearLayout or otherwise the items become selectable.
I was suspecting that touch listeners may be ineffective due to the fact that the swiping capability overrides any other kind of touch, but I can't really think of why it doesn't work otherwise. Can anyone help to resolve this issue? I would like to be able to use HorizontalScrollView alongside a click compatibility (unless there is another way to achieve the same functionality).
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<android.support.constraint.ConstraintLayout
android:id="#+id/constraintLayout4"
android:layout_width="384dp"
android:layout_height="110dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/task_view_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="17dp"
android:layout_marginTop="28dp"
android:fontFamily="#font/robotolight"
android:text="#string/task_name"
android:textColor="#android:color/black"
android:textSize="24sp"
app:layout_constraintStart_toEndOf="#+id/task_view_icon"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="#+id/task_view_icon"
android:layout_width="77dp"
android:layout_height="77dp"
android:layout_marginStart="17dp"
android:layout_marginTop="17dp"
android:contentDescription="#+string/icon"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="#drawable/main_page_icon_switch_x4" />
<TextView
android:id="#+id/task_view_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:layout_marginTop="36dp"
android:fontFamily="#font/robotolight"
android:text="#string/duration"
android:textColor="#android:color/black"
android:textSize="14sp"
app:layout_constraintStart_toEndOf="#+id/task_view_name"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="#+id/task_view_detail"
android:layout_width="228dp"
android:layout_height="31dp"
android:layout_marginStart="17dp"
android:fontFamily="#font/robotolight"
android:text="#string/task_view_detail_literal"
android:textColor="#android:color/black"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="#+id/task_view_icon"
app:layout_constraintTop_toBottomOf="#+id/task_view_name" />
</android.support.constraint.ConstraintLayout>
<android.support.constraint.ConstraintLayout
android:id="#+id/task_delete"
android:layout_width="116dp"
android:layout_height="110dp"
android:background="#color/colorPrimary"
app:layout_constraintEnd_toEndOf="#id/constraintLayout4"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="#+id/task_delete_literal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="13dp"
android:layout_marginTop="39dp"
android:fontFamily="#font/roboto_regular"
android:text="#string/delete"
android:textColor="#android:color/background_light"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>
</HorizontalScrollView>
For anyone having this problem, I managed to find a way to workaround this. My problem was that I could not click on the ListView item because of the HorizontalScrollView setup in the XML, however in my case I was using an adapter along with my ListView (that allows you link your listView with your actual list row view) and in that adapter I simply defined and linked the container of the view that I want to press and set an onClickListener.
This goes in your custom adapter:
ConstraintLayout myLayout = convertView.findViewById(R.id.constraintLayout1);
ConstraintLayout anotherLayout = convertView.findViewById(R.id.constraintLayout2); //lets' say I'm using this to delete the item when clicked
myLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent exampleIntent = new Intent(viewParent.getContext(), SomeActivity.class);
}
});
anotherLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(view.getContext());
builder.setMessage("Are You Sure?").setNegativeButton("No", null);
builder.setPositiveButton("yes", new android.support.v7.app.AlertDialog.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Database database = new Database(viewParent.getContext());
database.deleteItem(item);
List<Item> items = database.getItems();
ListView list = (ListView) viewParent.findViewById(R.id.my_linear_list);
//List<Item> items = new Database(viewParent.getContext()).getItems();
TaskAdapter adapterNew = new ItemAdapter(viewParent.getContext(), tasks);
list.setAdapter(adapterNew);
}
});
builder.show();
}
});

Categories

Resources