私は textview とcheckbox で行を作成した customlistadapter に取り組んでいます。リストは適切にレンダリングされていますが、ある項目を選択すると他の項目が自動的に選択され、リストをスクロールすると選択された項目が選択解除されます。
リストアダプターの私のコードは次のとおりです。
import java.util.ArrayList;
import com.example.interactiveapp.R;
import com.interactiveapp.Constants;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
public class FBContactlistAdapter extends BaseAdapter implements Filterable {
private LayoutInflater mInflater;
private ArrayList<Object> itemList;
private Activity _activity;
String contactName="";
String photoPath="";
String emailId="";
public FBContactlistAdapter(Activity activity, ArrayList<Object> itemList) {
this._activity = activity;
this.itemList = itemList;
mInflater = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public int getCount() {
return itemList != null ? itemList.size(): 0;
}
public Object getItem(int position) {
return itemList.get(position);
}
public Filter getFilter() {
return null;
}
public long getItemId(int position) {
return 0;
}
static class ViewHolder {
CheckBox checkBox;
TextView emailTxt;
}
public View getView(final int position, View convertView, ViewGroup parent) {
final ContactBean contactBean=(ContactBean)getItem(position);
final ViewHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.fb_contact_list_row, null);
holder = new ViewHolder();
holder.checkBox = (CheckBox)convertView.findViewById(R.id.checkBox1);
holder.emailTxt = (TextView)convertView.findViewById(R.id.username_txt);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.emailTxt.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
emailId=contactBean.getEmailId();
if(contactBean.isSelected==false){
contactBean.setSelected(true);
holder.checkBox.setChecked(true);
Constants.fbContactListArrayList.set(position, contactBean);
}else{
contactBean.setSelected(false);
holder.checkBox.setChecked(false);
Constants.fbContactListArrayList.set(position, contactBean);
}
}
});
//SET VALUES ON LIST VIEW
emailId=contactBean.getEmailId();
if(emailId.length()!=0 ||emailId!=null){
holder.emailTxt.setText(emailId);
}
return convertView;
}
//HANDLER
private Handler _handler = new Handler() {
public void dispatchMessage(Message msg) {
switch (msg.arg1) {
case 123:
break;
default:
break;
}
}
};
public void serverResponse(String response, int processid) {
Message msg = new Message();
msg.arg1 = processid;
msg.obj = response;
_handler.dispatchMessage(msg);
}
/*//SEND EMAIL TO INVITE FRIEND
public void sendEmail(String emailId){
Intent intent = new Intent(Intent.ACTION_SEND);
//intent.setType("text/plain");
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, emailId);
intent.putExtra(Intent.EXTRA_SUBJECT,Constant.EMAIL_SUBJECT);
intent.putExtra(Intent.EXTRA_TEXT, Constant.EMAIL_CONTENT);
_activity.startActivity(Intent.createChooser(intent, "Send Email"));
}*/
}