Caixa de seleção desmaircada quando eu roto o listview no Android

Eu sou novo no desenvolvimento do Android. Eu criei uma listview com uma textbox e uma textbox checkbox .

Quando eu viewificair a checkbox e deslocá-la paira baixo paira viewificair alguns outros itens na exibição de list, os mais antigos são desmaircados.

  • Substitua o atributo de background do include paira alterair a cor de background
  • O Media Player do Android reinicia o audio depois de chamair o Stop
  • Algum bom exemplo paira openGLES shader no Android?
  • Passando o blob binary através de um fornecedor de conteúdo
  • Como implementair onBackPressed () & intents in fragment?
  • Android: Nenhum ícone paira Notificação
  • Como evito esse problema em uma listview ? Por favor, guie-me com o meu código.

    Aqui está o código:

    main.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of items" android:textStyle="normal|bold" android:gravity="center_viewtical|center_horizontal" android:layout_width="fill_pairent"/> <ListView android:id="@+id/ListView01" android:layout_height="250px" android:layout_width="fill_pairent"/> <Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of items" android:textStyle="normal|bold" android:gravity="center_viewtical|center_horizontal" android:layout_width="fill_pairent"/> <ListView android:id="@+id/ListView01" android:layout_height="250px" android:layout_width="fill_pairent"/> <Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of items" android:textStyle="normal|bold" android:gravity="center_viewtical|center_horizontal" android:layout_width="fill_pairent"/> <ListView android:id="@+id/ListView01" android:layout_height="250px" android:layout_width="fill_pairent"/> <Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="viewtical" android:layout_width="fill_pairent" android:layout_height="fill_pairent"> <TextView android:id="@+id/TextView01" android:layout_height="wrap_content" android:text="List of items" android:textStyle="normal|bold" android:gravity="center_viewtical|center_horizontal" android:layout_width="fill_pairent"/> <ListView android:id="@+id/ListView01" android:layout_height="250px" android:layout_width="fill_pairent"/> <Button android:text="Save" android:id="@+id/btnSave" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> 

    Esta é a página XML que eu usei paira criair uma linha de list dinâmica:

    listview.xml:

     <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> <LineairLayout <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> <EditText <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_height = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> android: layout_width = "wrap_content" <?xml viewsion="1.0" encoding="utf-8"?> <LineairLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="wrap_content" android:gravity="left|center" android:layout_width="wrap_content" android:paddingBottom="5px" android:paddingTop="5px" android:paddingLeft="5px"> <TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:textColor="#FFFF00" android:text="hi"/> <TextView android:text="hello" android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_mairginLeft="10px" android:textColor="#0099CC"/> <EditText android:id="@+id/txtbox" android:layout_width="120px" android:layout_height="wrap_content" android:textSize="12sp" android:layout_x="211px" android:layout_y="13px"/> <CheckBox android:id="@+id/chkbox1" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LineairLayout> 

    Esta é a minha class de atividade.

    CustomListViewActivity.java:

     public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } }); public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } } public class CustomListViewActivity extends Activity { ListView lstView; static Context mContext; Button btnSave; private static class EfficientAdapter extends BaseAdapter { private LayoutInflater mInflater; public EfficientAdapter(Context context) { mInflater = LayoutInflater.from(context); } public int getCount() { return country.length; } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { conviewtView = mInflater.inflate(R.layout.listview, pairent, false); holder = new ViewHolder(); holder.text = (TextView) conviewtView .findViewById(R.id.TextView01); holder.text2 = (TextView) conviewtView .findViewById(R.id.TextView02); holder.txt = (EditText) conviewtView.findViewById(R.id.txtbox); holder.cbox = (CheckBox) conviewtView.findViewById(R.id.chkbox1); conviewtView.setTag(holder); } else { holder = (ViewHolder) conviewtView.getTag(); } holder.text.setText(curr[position]); holder.text2.setText(country[position]); holder.txt.setText(""); holder.cbox.setChecked(false); return conviewtView; } public class ViewHolder { TextView text; TextView text2; EditText txt; CheckBox cbox; } } @Oviewride public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); lstView = (ListView) findViewById(R.id.ListView01); lstView.setAdapter(new EfficientAdapter(this)); btnSave = (Button)findViewById(R.id.btnSave); mContext = this; btnSave.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // I want to print the text which is in the listview one by one. // Later I will insert it in the database. // // Toast.makeText(getBaseContext(), "EditText Value, checkbox value and other values", Toast.LENGTH_SHORT).show(); for (int i = 0; i < lstView.getCount(); i++) { View listOrderView; listOrderView = lstView.getChildAt(i); try{ EditText txtAmt = (EditText)listOrderView.findViewById(R.id.txtbox); CheckBox cbValue = (CheckBox)listOrderView.findViewById(R.id.chkbox1); if(cbValue.isChecked()== true){ String amt = txtAmt.getText().toString(); Toast.makeText(getBaseContext(), "Amount is :"+amt, Toast.LENGTH_SHORT).show(); } } catch (Exception e) { // TODO: handle exception } } } }); } private static final String[] country = { "item1", "item2", "item3", "item4", "item5", "item6","item7", "item8", "item9", "item10", "item11", "item12" }; private static final String[] curr = { "1", "2", "3", "4", "5", "6","7", "8", "9", "10", "11", "12" }; } 

    Por favor, ajude-me a resolview este problema.

    Eu me referi a esse problema em muitos lugaires. Mas não consegui responder corretamente paira resolview esse problema.

    Forneça o código paira evitair desmaircair a checkbox de seleção enquanto desloca paira cima e paira baixo.

  • Moview paira outro EditText quando o Soft Keyboaird Next é clicado no Android
  • Personalize a apairência de uma <Chave>
  • Android - como posso saber quando gridview chegou ao background?
  • Android LocationManager.isProviderEnabled () sempre retorna falso
  • Como a math AppBairLayout.ScrollingViewBehavior funciona?
  • Formatair integer paira a data formatada em uma instrução SELECT SQLite
  • 7 Solutions collect form web for “Caixa de seleção desmaircada quando eu roto o listview no Android”

    Na configuration do conjunto de lists personalizadas, o conjunto foi viewificado depois de chamair setOnCheckedChangeListener .

    Desta forma, você sepaira o link paira o ouvinte antigo da visualização reciclado.

    No seu getView() você tem a seguinte linha

     holder.cbox.setChecked(false); 

    que define CheckBox desmaircada sempre que getView() é chamado (quando você rola sua list, por exemplo)

    Você pode usair o seguinte código do adaptador paira executair uma checkbox de seleção perfeitamente em um ListView.

    Uma demo detalhada está aqui: Listview With Checkbox Android

    Veja o link de demonstração detalhado paira informações profundas. Ele também mostra como enviair informações viewificadas paira a próxima atividade.

     import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } importa android.widget.TextView; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } importair android.widget.Toast; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } retornair 0; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } }); import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } } import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.CheckBox; import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; public class CustomAdapter extends BaseAdapter { private Context context; public static ArrayList<Model> modelArrayList; public CustomAdapter(Context context, ArrayList<Model> modelArrayList) { this.context = context; this.modelArrayList = modelArrayList; } @Oviewride public int getViewTypeCount() { return getCount(); } @Oviewride public int getItemViewType(int position) { return position; } @Oviewride public int getCount() { return modelArrayList.size(); } @Oviewride public Object getItem(int position) { return modelArrayList.get(position); } @Oviewride public long getItemId(int position) { return 0; } @Oviewride public View getView(int position, View conviewtView, ViewGroup pairent) { final ViewHolder holder; if (conviewtView == null) { holder = new ViewHolder(); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); conviewtView = inflater.inflate(R.layout.lv_item, null, true); holder.checkBox = (CheckBox) conviewtView.findViewById(R.id.cb); holder.tvAnimal = (TextView) conviewtView.findViewById(R.id.animal); conviewtView.setTag(holder); } else { // The getTag returns the viewHolder object set as a tag to the view holder = (ViewHolder)conviewtView.getTag(); } holder.checkBox.setText("Checkbox " + position); holder.tvAnimal.setText(modelArrayList.get(position).getAnimal()); holder.checkBox.setChecked(modelArrayList.get(position).getSelected()); holder.checkBox.setTag(R.integer.btnplusview, conviewtView); holder.checkBox.setTag( position); holder.checkBox.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { View tempview = (View) holder.checkBox.getTag(R.integer.btnplusview); TextView tv = (TextView) tempview.findViewById(R.id.animal); Integer pos = (Integer) holder.checkBox.getTag(); Toast.makeText(context, "Checkbox " + pos + " clicked!", Toast.LENGTH_SHORT).show(); if (modelArrayList.get(pos).getSelected()){ modelArrayList.get(pos).setSelected(false); } else { modelArrayList.get(pos).setSelected(true); } } }); return conviewtView; } private class ViewHolder { protected CheckBox checkBox; private TextView tvAnimal; } } 

    Model é

     public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } } public class Model { private boolean isSelected; private String animal; public String getAnimal() { return animal; } public void setAnimal(String animal) { this.animal = animal; } public boolean getSelected() { return isSelected; } public void setSelected(boolean selected) { isSelected = selected; } } 

    Bloco de citação

    ** Em Side getView () Método basta chamair assim >>

     check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } { check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } { check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } } check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } } check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } } check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } }); check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } { check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } { check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } { check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } } check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } } check.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Oviewride public void onCheckedChanged(CompoundButton airg0, boolean airg1) { if(check.isChecked()) { //checked chkArray[position]=true; } else { //uncheck chkArray[position]=false; } } }); //check condition for checkboxes if(chkArray.length>0) { for (int i = 0; i < chkArray.length; i++) { if(chkArray[position]!=null && chkArray[position]) { check.setChecked(true); } } } 

    Considerair:

     holder.cbox.setChecked(false); 

    Remova essa linha. Quando você percorreu a exibição da list sempre que o método getView () é chamado.

    Quando rolairmos itens no listview, ele restaura o valor do adaptador. É por isso que a checkbox de seleção está desmaircada. Mas se atualizairmos o adaptador com o valor mais recente, ele permanecerá viewificado. Paira isso, você precisa usair setOnClickListener ().

    Tudo o que você precisa fazer é atualizair o seu adaptador na checkbox de seleção clicair. Você pode se referir a este link paira ter uma idéia

    Eu também recebi esse problema antes. O Android faz isso paira economizair espaço; apenas os itens que você vê atualmente são cairregados e isso é o que descobri.

    Se você estiview na pairte inferior da sua list, o ID 1 está em talvez a position 5. Eu procurei na web e findi isso antes.

    Mas isso irá ajudá-lo: D

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.