I am having a activity and in same activity I have a array adapter class with checkbox. As you can see I get the data from webservice. So after parsing the json data I get the userIDs in string array uid[]. Now I have the checkbox in sendinvitesadapter. I have to set tag the checkbox with string array uid[]. So that when user clicks on first checkbox it should get assigned with first value from uid[] and so on... How Can I do this. I know it can be done using set tag and get tag. but I am facing errors. Its only taking the last value from uid[] and same is assinged to all of the checkboxes.
public class qrusers extends ActivityGroup{
EditText usersearch;
ArrayList<Item> items = new ArrayList<Item>();
ListView listView;
static InputStream is = null;
final ArrayList<String> list = new ArrayList<String>();
CheckBox checkBox;
String result;
Button addusers;
private String[] name,email,phone,date,company,combine;
public static String[] uid;
CheckBox qrcheckBox;
sendivitesadapter sendadapter;
@Override
public void onBackPressed() {
// TODO Auto-generated method stub
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.qrusers);
usersearch=(EditText)findViewById(R.id.usersearch);
listView=(ListView)findViewById(R.id.qruserlist);
addusers=(Button)findViewById(R.id.addusers);
addusers.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
}
});
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnected()){
saveThread saveTask= new saveThread();
saveTask.execute(new String[] { "url"});
}
}
public class sendivitesadapter extends ArrayAdapter<Item>{
private Context context;
private ArrayList<Item> items;
private qrusers qrusers;
private LayoutInflater vi;
private String[] array;
qrusers qrus;
public sendivitesadapter(Context context,ArrayList<Item> items) {
super(context, 0,items);
this.context= context;
this.qrusers =(qrusers) context;
this.items = items;
vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return super.getCount();
}
@Override
public Item getItem(int position) {
// TODO Auto-generated method stub
return super.getItem(position);
}
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
View v = convertView;
final Item i = items.get(position);
if (i != null) {
if(i.isSection()){
SectionItem si = (SectionItem)i;
v = vi.inflate(R.layout.checkboxlist, null);
v.setOnClickListener(null);
v.setOnLongClickListener(null);
v.setLongClickable(false);
final TextView sectionView = (TextView) v.findViewById(R.id.list_item_section_text);
sectionView.setText(si.getTitle());
}else{
sendItem ei = (sendItem)i;
v = vi.inflate(R.layout.checkboxlist, null);
final TextView title = (TextView)v.findViewById(R.id.contactname);
final TextView subtitle = (TextView)v.findViewById(R.id.companyname);
checkBox=(CheckBox)v.findViewById(R.id.checboxlist);
//checkBox.setTag(position);
//items.addAll(uid);
// Log.e("IDDDDDDD", text);
//checkBox.setTag("12");
checkBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String s= (String)v.getTag();
Log.e("IDDDDDDDDDDDDDDDDDDDDDD", s);
}
});
if (title != null)
title.setText(ei.contactname);
if(subtitle != null)
subtitle.setText(ei.companyname);
}
}
return v;
}
}
public void replaceContentView(String id, Intent newIntent) {
View view = getLocalActivityManager().startActivity(id,
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP))
.getDecorView();
this.setContentView(view);
}
class saveThread extends AsyncTask<String, Void, String>{
@Override
protected String doInBackground(String... urls) {
Context context;
String response = "";
for (String url : urls) {
DefaultHttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
HttpResponse response1;
try {
response1 = client.execute(httpGet);
HttpEntity entity = response1.getEntity();
is = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(is, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
result = sb.toString();
System.out.println(result);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return result;
}
@Override
protected void onPostExecute(String result) {
JSONArray jarray;
try {
jarray= new JSONArray(result);
name= new String[jarray.length()];
company=new String[jarray.length()];
uid=new String[jarray.length()];
for (int i=0;i<jarray.length();i++){
JSONObject jobj = jarray.getJSONObject(i);
name[i]= jobj.getString("Name");
company[i]=jobj.getString("Company");
uid[i]=jobj.getString("UserID");
System.out.println(uid[i]);
items.add(new sendItem(name[i], company[i], qrcheckBox));
sendadapter = new sendivitesadapter(qrusers.this,items);
listView.setAdapter(sendadapter);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
super.onPostExecute(result);
}
}
}