I have two activities A and B,In my Activity A i have one button user will click on that button and redirect to B
This is my Activity A
public class NewsActi extends AppCompatActivity{
private Button txtvw;
public final static int GO_FOR_SORTINGDATA = 909;
private String fid;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news_act);
txtvw = (Button) findViewById(R.id.button);
if(getIntent().getExtras()!=null)
{
fid=getIntent().getStringExtra("filterid");
}
else
{
System.out.println("NewsActi is null");
}
System.out.println("NewsActi"+fid);
txtvw.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intentF = new Intent(NewsActi.this, MainActivity.class);
if (fid != null) {
intentF.putExtra("updtfiltid", fid);
} else {
intentF.putExtra("updtfiltid", "null");
}
startActivityForResult(intentF,GO_FOR_SORTINGDATA);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK) {
switch (requestCode)
{
case GO_FOR_SORTINGDATA:
try {
fid=data.getStringExtra("filterid");
if(fid!=null)
{
System.out.println("FILTER IN PRODUCTLIST" + fid);
}
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
}
Now In my Activity B i have listview with checkbox, and i am parsing data and display it. Now Issue is first when i go to B and select two items and then click on button and sending selected ids to Activity A,now again i am going to B and and uncheck one selected item,and check another item from list.but still previously selected item is getting when i click on button.
Activity B
btnSelection.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View v) {
String data = "";
List<ModelUser> stList = ((MyCustomAdapter) mAdapter)
.getStudentist();
for (int i = 0; i < stList.size(); i++) {
ModelUser singleStudent = stList.get(i);
if (singleStudent.isSelected() == true) {
data = data+singleStudent.getId() +",";
}
}
System.out.println("my data"+data);
if(fid.equals("null"))
{
System.out.println("if data"+data);
}
else
{
data=fid+data;
System.out.println("else data"+data);
}
Intent intent=new Intent(MainActivity.this,NewsActi.class);
intent.putExtra("filterid",data);
setResult(RESULT_OK, intent);
MainActivity.this.finish();
Toast.makeText(MainActivity.this, data, Toast.LENGTH_LONG).show();
}
});
} catch (JSONException e) {
e.printStackTrace();
}
}
Aucun commentaire:
Enregistrer un commentaire