Manoj Gayakwad
Manoj Gayakwad

Reputation: 3

How to get text from textbox onclick checkbox in listview using android

I am working on checkbox example. I have checkbox and textview (The textview value is I am getting from database) in ListView by using that when I click on checkbox then I am getting text of textview but it's returning only text id not value. Also, I want to get text in textview or unique id of particular row where I click in the front of checkbox and it's getting same id for all textview. Please help me get unique id or text from textview.

Code for click checkbox event

  public void onCheckboxClicked(View view) {

    // Is the view now checked?
    boolean checked = ((CheckBox) view).isChecked();

    switch(view.getId()) {
        case R.id.checkbox_me:
            if (checked) {
                //Toast.makeText(getApplicationContext(), "'checkbox me..", Toast.LENGTH_LONG).show();
                username = (TextView)findViewById(R.id.inactivelistview);

                Username =username.getText().toString();
                System.out.println("prinnt username_=== "+username);

                AlertDialog.Builder alertbox = new AlertDialog.Builder(this);
                alertbox.setMessage("Do you want activate?");

                alertbox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                      public void onClick(DialogInterface arg0, int arg1) {
                        Toast.makeText(getApplicationContext(), "'Yes' button clicked", Toast.LENGTH_SHORT).show();
                    }

                });

                alertbox.setNegativeButton("No", new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface arg0, int arg1) {
                        Toast.makeText(getApplicationContext(), "'No' button clicked", Toast.LENGTH_SHORT).show();
                    }
                });
               alertbox.show();
            } else
                break;
    }
}

listadapter xml code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
    android:id="@+id/inactivelistview"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textColor="#429ed7"
    android:textSize="18sp"
    />

<CheckBox android:id="@+id/checkbox_me"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onCheckboxClicked"/>

When I click on check box it checks, if check then in username String it returns the id of textview for all checkbox click event, but I want the text value in checkbox. I tried lots of method but not working please help me if you have any idea,.

Upvotes: 0

Views: 681

Answers (1)

soissy
soissy

Reputation: 78

I think that in this point

System.out.println("prinnt username_=== "+username);

you have to put "Username" instead of "username":

System.out.println("prinnt username_=== "+Username);

Upvotes: 1

Related Questions