Note that there are some explanatory texts on larger screens.

plurals
  1. POIssue With android ListView
    primarykey
    data
    text
    <p>I have added a listadapter which contains a checkbox, imageview, two textviews and a button to a listview. The problem is when I click on single checkbox for selecting more than one is getting selected. Below is my code for the Adapter. Please tell me any thing wrong in the code.</p> <pre><code>package com.mgm.schannel.lazylist; import java.util.ArrayList; import java.util.List; import com.mgm.schannel.R; import com.mgm.schannel.fonts.FontUtil; import com.mgm.schannel.parser.inbox.Child; import com.mgm.schannel.parser.inbox.Messages; import com.mgm.schannel.ui.inboxActivity; import android.content.Context; import android.graphics.Color; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.CheckBox; import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; import android.widget.CompoundButton.OnCheckedChangeListener; public class InboxAdapter extends BaseAdapter { public ArrayList&lt;Object&gt; getSelectedItems() { return selectedItems; } private ArrayList&lt;Object&gt; selectedItems; private inboxActivity activity; private List&lt;Object&gt; data; private static LayoutInflater inflater = null; private TextView MessageCount; FontUtil fontsList; private boolean showMoveButton; int positionItem; public TextView getMessageCount() { return MessageCount; } public InboxAdapter(inboxActivity a, List&lt;Object&gt; results, FontUtil fontslist) { activity = a; data = results; fontsList = fontslist; inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE); showMoveButton = false; selectedItems = new ArrayList&lt;Object&gt;(); } public int getCount() { return data.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public View getView(int position, View convertView, ViewGroup parent) { View vi = convertView; Object inboxObject = data.get(position); positionItem = position; if(convertView == null) vi = inflater.inflate(R.layout.inboxlist, null); Button btnmove = (Button)vi.findViewById(R.id.btnmovehere); if(position % 2 == 0) { vi.setBackgroundColor(Color.parseColor("#ebebeb")); } else { vi.setBackgroundColor(Color.parseColor("#f4f4f4")); } if(inboxObject instanceof Messages) { ImageView imgicon = (ImageView)vi.findViewById(R.id.inboxicon); imgicon.setImageResource(R.drawable.message); TextView text = (TextView)vi.findViewById(R.id.txtCaption); text.setTextSize(16.f); text.setTextColor(Color.BLACK); text.setTypeface(fontsList.getTitilliumMaps29L002()); text.setText(((Messages)inboxObject).getSender()); text = (TextView)vi.findViewById(R.id.txtMessage); text.setTextSize(10.f); text.setTextColor(Color.BLACK); text.setTypeface(fontsList.getTitilliumMaps29L002()); text.setText(((Messages)inboxObject).getMessage()); btnmove.setVisibility(View.INVISIBLE); CheckBox cbSelected = (CheckBox)vi.findViewById(R.id.chkSelection); cbSelected.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(buttonView.isChecked()) { getSelectedItems().add(data.get(positionItem)); } } }); } else if(inboxObject instanceof Child) { TextView text = (TextView)vi.findViewById(R.id.txtCaption); text.setTextSize(14.f); text.setTextColor(Color.BLACK); text.setTypeface(fontsList.getTitilliumMaps29L002()); Log.e("Folder Name", ((Child)inboxObject).getFolderName()); text.setText(((Child)inboxObject).getFolderName()); ImageView imgicon = (ImageView)vi.findViewById(R.id.inboxicon); imgicon.setImageResource(R.drawable.folder); text = (TextView)vi.findViewById(R.id.txtMessage); text.setVisibility(View.GONE); if(showMoveButton) { btnmove.setVisibility(View.VISIBLE); } else { btnmove.setVisibility(View.INVISIBLE); } CheckBox cbSelected = (CheckBox)vi.findViewById(R.id.chkSelection); cbSelected.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub if(buttonView.isChecked()) { getSelectedItems().add(data.get(positionItem)); } } }); } return vi; } public void showMove(boolean value) { showMoveButton = value; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload