Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8056457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:42:30+00:00 2026-06-05T08:42:30+00:00

I have Checkbox and EditText and a Textview in a listView. It gets value

  • 0

I have Checkbox and EditText and a Textview in a listView. It gets value for the text view from a list. Checkbox will be checked dynamically. In the same way EditText also can be entered dynamically. Now my problem is, When i scroll the list view (up and down) after entering the text in the Edit text, I could not get the typed value. I check the check box also like that. But using the position, I set it correct. I Could not know How to set the EditText value to the list properly. Please help me. Here is my code:

main.xml: (Main xml for launch)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ListView
android:id="@+id/my_list"
android:layout_width="fill_parent"
android:layout_height="250px" />
<Button 
android:text="Save" 
android:id="@+id/btnSave" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"/>

</LinearLayout>

row.xml: (ListView Row)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:textSize="30sp"/>

<CheckBox
android:id="@+id/check"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText 
android:text=""
android:id="@+id/txtAddress"
android:layout_width="150px"
android:layout_height="wrap_content"/>
</LinearLayout>

Model.Java: (It is the POJO class)

package com.checkboxlistview;

public class Model {

private String name;
private boolean selected;
private String address;

public String getAddress() {
    return address;
}

public void setAddress(String address) {
    this.address = address;
}

public void setName(String name) {
    this.name = name;
}

public Model(String name) {
    this.name = name;
}

public String getName() {
    return name;
}

public boolean isSelected() {
    return selected;
}

public void setSelected(boolean selected) {
    this.selected = selected;
}

}

MyAdapter.Java: (This is used to Hold the view in the list view using the converter and holder)

package com.checkboxlistview;

import java.util.List;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;

public class MyAdapter extends ArrayAdapter<Model> implements TextWatcher {

private final List<Model> list;
private final Activity context;
int listPosititon;

public MyAdapter(Activity context, List<Model> list) {
    super(context, R.layout.row, list);
    this.context = context;
    this.list = list;
}

static class ViewHolder {
    protected TextView text;
    protected CheckBox checkbox;
    protected EditText address;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    listPosititon = position;
    ViewHolder viewHolder = null;
    if (convertView == null) {
        LayoutInflater inflator = context.getLayoutInflater();
        convertView = inflator.inflate(R.layout.row, null);
        viewHolder = new ViewHolder();
        viewHolder.text = (TextView) convertView.findViewById(R.id.label);
        viewHolder.checkbox = (CheckBox) convertView
                .findViewById(R.id.check);
        viewHolder.address = (EditText) convertView
                .findViewById(R.id.txtAddress);
        viewHolder.checkbox
                .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
int getPosition = (Integer) buttonView.getTag(); 
//Here we get the position that we have  set for the checkbox using setTag.
list.get(getPosition).setSelected(
buttonView.isChecked()); 
// Set the value of checkbox to maintain its state.
}
});
        viewHolder.address.addTextChangedListener(this);

        convertView.setTag(viewHolder);
        convertView.setTag(R.id.label, viewHolder.text);
        convertView.setTag(R.id.check, viewHolder.checkbox);
        convertView.setTag(R.id.txtAddress, viewHolder.address);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
    }
    viewHolder.checkbox.setTag(position); // This line is important.

    viewHolder.text.setText(list.get(position).getName());
    viewHolder.checkbox.setChecked(list.get(position).isSelected());
    if (list.get(position).getAddress() != null) {
        viewHolder.address.setText(list.get(position).getAddress() + "");
    } else {
        viewHolder.address.setText("");
    }

    return convertView;
}

@Override
public void afterTextChanged(Editable s) {
    list.get(listPosititon).setAddress(s.toString());
}

@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
        int arg3) {
    // TODO Auto-generated method stub

}

@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
    // TODO Auto-generated method stub

}
}

MainActivity.java (This is the activity):

package com.checkboxlistview;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity extends Activity { 
 ListView listView;
 Button btnSave;
    ArrayAdapter<Model> adapter;
    List<Model> list = new ArrayList<Model>();

    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        listView = (ListView) findViewById(R.id.my_list);
        btnSave = (Button)findViewById(R.id.btnSave);
        adapter = new MyAdapter(this,getModel());
        listView.setAdapter(adapter);
        btnSave.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                for (int i = 0; i < list.size(); i++) {
                    Toast.makeText(getBaseContext(), "Name : "+list.get(i).getName() +" Selected: "+list.get(i).isSelected(), Toast.LENGTH_SHORT).show();

                }
            }
        });
    }


    private List<Model> getModel() {
        list.add(new Model("Linux"));
        list.add(new Model("Windows7"));
        list.add(new Model("Suse"));
        list.add(new Model("Eclipse"));
        list.add(new Model("Ubuntu"));
        list.add(new Model("Solaris"));
        list.add(new Model("Android"));
        list.add(new Model("iPhone"));
        list.add(new Model("Java"));
        list.add(new Model(".Net"));
        list.add(new Model("PHP"));
        return list;
    }
}

There is no error in the code. It runs well. I could maintain the checkbox position and display at the same position even I scroll up and down. But I could not get and set the EditText value properly. Please Help me out.
Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:42:31+00:00Added an answer on June 5, 2026 at 8:42 am

    you can achieve this using the custom list view.

    find the example of listview with edittext is here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to copy the text from one text box to another using checkbox
I have this checkBox in my view inside a form: <g:checkBox name=myCheckbox value=${false} />
The main.xml file code: <TableRow android:id=@+id/TableRow01 android:layout_width=wrap_content android:layout_height=wrap_content> <TextView android:text=User android:id=@+id/TextView01 android:layout_width=wrap_content android:layout_height=wrap_content></TextView> <EditText
So, my app reads Data from the text view and then saves it to
i have a boolean[] , checkbox[] , and view[] ( impactsb[] , impactsc[] ,
I have a checkbox in GridViewColumn which i use for show/change database value. The
I have a checkbox list control on my asp.net web form that I am
I have a checkbox and radiobuttonlist defined as follows: <asp:CheckBox id=chkChange runat=server text=Enable />
I have a checkbox when user checked that check box means. I need to
I need to create edittext fields dynamically in android. I have gone through the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.