Note that there are some explanatory texts on larger screens.

plurals
  1. POListview selects mutliple items when clicked
    primarykey
    data
    text
    <p>I'm trying to make a task manager, and I only have one problem. I have a listview that gets inflated. All the elements in the listview are correct. The problem is that when I select an item, the listview will select another item away. I've heard listviews repopulate the list as it scrolls down to save memory. I think this may be some sort of problem. Here is a picture of the <a href="http://imgur.com/9r3hE.jpg" rel="nofollow"><strong>problem</strong></a>. If i had more apps loaded, then it would continue to select multiple at once.</p> <p>Here is the code of my adapter and activity and XML associated</p> <pre><code>public class TaskAdapter extends BaseAdapter{ private Context mContext; private List&lt;TaskInfo&gt; mListAppInfo; private PackageManager mPack; public TaskAdapter(Context c, List&lt;TaskInfo&gt; list, PackageManager pack) { mContext = c; mListAppInfo = list; mPack = pack; } @Override public int getCount() { return mListAppInfo.size(); } @Override public Object getItem(int position) { return mListAppInfo.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(final int position, View convertView, ViewGroup parent) { TaskInfo entry = mListAppInfo.get(position); if (convertView == null) { LayoutInflater inflater = LayoutInflater.from(mContext); //System.out.println("Setting LayoutInflater in TaskAdapter " +mContext +" " +R.layout.taskinfo +" " +R.id.tmbox); convertView = inflater.inflate(R.layout.taskinfo,null); } ImageView ivIcon = (ImageView)convertView.findViewById(R.id.tmImage); ivIcon.setImageDrawable(entry.getIcon()); TextView tvName = (TextView)convertView.findViewById(R.id.tmbox); tvName.setText(entry.getName()); convertView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { final CheckBox checkBox = (CheckBox)v.findViewById(R.id.tmbox); if(v.isSelected()) { System.out.println("Listview not selected "); //CK.get(arg2).setChecked(false); checkBox.setChecked(false); v.setSelected(false); } else { System.out.println("Listview selected "); //CK.get(arg2).setChecked(true); checkBox.setChecked(true); v.setSelected(true); } } }); return convertView; public class TaskManager extends Activity implements Runnable { private ProgressDialog pd; private TextView ram; private String s; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.taskpage); setTitleColor(Color.YELLOW); Thread thread = new Thread(this); thread.start(); } @Override public void run() { //System.out.println("In Taskmanager Run() Thread"); final PackageManager pm = getPackageManager(); final ListView box = (ListView) findViewById(R.id.cBoxSpace); final List&lt;TaskInfo&gt; CK = populate(box, pm); runOnUiThread(new Runnable() { @Override public void run() { ram.setText(s); box.setAdapter(new TaskAdapter(TaskManager.this, CK, pm)); //System.out.println("In Taskmanager runnable Run()"); endChecked(CK); } }); handler.sendEmptyMessage(0); } </code></pre> <p>Taskinfo.xml</p> <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:gravity="center_horizontal"&gt; &lt;ImageView android:id="@+id/tmImage" android:layout_width="48dp" android:layout_height="48dp" android:scaleType="centerCrop" android:adjustViewBounds="false" android:focusable="false" /&gt; &lt;CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/tmbox" android:lines="2"/&gt; &lt;/LinearLayout&gt; </code></pre> <p>Taskpage.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"&gt; &lt;ListView android:id="@+id/cBoxSpace" android:layout_width="wrap_content" android:layout_height="400dp" android:orientation="vertical"/&gt; &lt;TextView android:id="@+id/RAM" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" /&gt; &lt;Button android:id="@+id/endButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="End Selected Tasks" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>Any ideas for what reason mutliple items are selected with a single click would be GREATLY appreciated. I've been messing around with different implementations and listeners and listadapters but to no avail.</p>
    singulars
    1. This table or related slice is empty.
    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