Saturday, April 12, 2014

android multiple CheckBox (over the entire screen) Select and anti-choice questions


android in ListView under multiple CheckBox Select problem, if the number is more than one screen CheckBox, some are selected, not selected parts of the problem occurs, ask the experts how to solve?
<-! Main posts under Banner (D4) -><-! Posts under the main text (D5) ->
Reply:
It is not that a state record it? The reason is certainly not set on the state.
Reply:
In a group which will be out of the question?
Reply:
This problem, I have not met
Reply:
How much checkbox is automatically generated based on the number of recording data in the database. Without whether to rewrite Adapter can solve this problem?
Reply:
Have not encountered over the CheckBox try fullscreen
Reply:
Please fulcrum move it!
Reply:
Put your code to select all unselected Tieshanglai see it
Mainly to see how to deal with
Adapter Lane
The most stupid way: ListView instance method to find instances of child checkbox, and then one by one set, it should be no problem
Reply:
Need to customize the ListView MyAdapter
 
/ *
* Custom ListView's MyAdapter
* /
public final class ViewHolder {
public TextView iid;
public EditText info;
public CheckBox cbx;
public ImageView img;

}

Set selectedSet = new HashSet (); / / focus

public class MyAdapter extends BaseAdapter {

private LayoutInflater mInflater;

public MyAdapter (Context context) {
this.mInflater = LayoutInflater.from (context);
}

@ Override
public int getCount () {
return mData.size ();
}

@ Override
public Object getItem (int position) {
return mData.get (position);
}

@ Override
public long getItemId (int arg0) {
return arg0;
}

@ Override
public View getView (final int position, View convertView,
ViewGroup parent) {

ViewHolder holder = null;
if (convertView == null) {

holder = new ViewHolder ();

convertView = mInflater.inflate (R.layout.marklist, null);
holder.iid = (TextView) convertView.findViewById (R.id.iid);
holder.info = (EditText) convertView.findViewById (R.id.info);

holder.cbx = (CheckBox) convertView.findViewById (R.id.cbx);

holder.img = (ImageView) convertView.findViewById (R.id.img);
convertView.setTag (holder);

} Else {

holder = (ViewHolder) convertView.getTag ();
}

holder.iid.setText (String.valueOf (mData.get (position) get ("iid")).);
holder.info.setText ((String) mData.get (position) get ("info").);

int resid = (Integer) mData.get (position) get ("img");.
if (resid! = 0)
holder.img.setBackgroundResource (resid);

holder.info.setText (mData.get (position) toString ().);

/ / Focus began
Object b = (Object) getItem (position);
if (b! = null) {
if (selectedSet.contains (b)) {
holder.cbx.setChecked (true);
} Else {
holder.cbx.setChecked (false);
}

}


holder.cbx.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View v) {
CheckBox cb = (CheckBox) v;
if (cb.isChecked ()) {
selectedSet.add ((Object) getItem (position));
} Else {
selectedSet.remove ((Object) getItem (position));
}
}
});
/ / End
focusholder.info.setOnClickListener (new View.OnClickListener () {
@ Override
public void onClick (View arg0) {
}
});

return convertView;
}

@ Override
public void notifyDataSetChanged () {
/ / TODO Auto-generated method stub
super.notifyDataSetChanged ();
}
}

I do not understand you can ask
Reply:
I know rewrite Adapter, I also realized function. Only such a solution?
Reply:
The reply was deleted at the moderator 2011-06-29 11:01:45

Reply:
Amount. . Finally see his reply to

Reply:
http://download.csdn.net/source/3120614 This is what you want
Reply:
Here is an example I used to see, this should be able to solve your problem now:
 package com.listViewTest; 

import java.util.ArrayList;
import java.util.List;
import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

public class ListViewTest extends ListActivity {
/ ** Called when the activity is first created. * /
Context context = null;
List list = new ArrayList ();
CheckBox checkbox;
private LinearLayout lr;

@ Override
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
context = getApplicationContext ();
setListAdapter (new MyListAdapter ());
}

@ Override
protected void onListItemClick (ListView l, View v, int position, long id) {
/ / TODO Auto-generated method stub
super.onListItemClick (l, v, position, id);
lr = (LinearLayout) v;
checkbox = (CheckBox) lr.getChildAt (1);
if (list.contains (new Integer (position))) {
checkbox.setChecked (false);
list.remove (new Integer (position));
} Else {
checkbox.setChecked (true);
list.add (new Integer (position));
}
}

class MyListAdapter extends BaseAdapter {
String data [] = new String [] {"apple", "pear", "banana", "orange", "apple", "pear", "banana", "orange", "apple", "pear", "banana", "orange"};
public int getCount () {
/ / TODO Auto-generated method stub
return data.length;
}

public Object getItem (int position) {
/ / TODO Auto-generated method stub
return data [position];
}

public long getItemId (int position) {
/ / TODO Auto-generated method stub
return position;
}

public View getView (int position, View convertView, ViewGroup parent) {
if (null == convertView) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService (Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate (R.layout.list_item, parent, false);
}
TextView text = (TextView) convertView.findViewById (R.id.info);
checkbox = (CheckBox) convertView.findViewById (R.id.checkstatus);
checkbox.setTag (new Integer (position));
text.setText (data [position]);
if (list! = null) {
checkbox.setChecked ((list.contains (new Integer (position))));
} Else {
checkbox.setChecked (false);
}
return convertView;
}
}
}

Reply:
The reply was deleted administrator at 2013-08-06 09:15:37

Reply:
You remove the cache that it should be cached problems

No comments:

Post a Comment