jeudi 19 février 2015

how can i delete messages from listview using checkbox without database from two different activities?

hey I want to delete messages from my listView using checkbox but iam unable because my delete button is in main activity and checkbox is in another activity as i have shown below...can anyone kindly help me out....!!!!



import java.util.ArrayList;
import java.util.List;

import com.PlumCitizenSMS.R;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.sax.StartElementListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
import android.widget.Toast;



public class ListAdapter extends BaseAdapter {
TextView smsMsg;
private LayoutInflater mLayoutInflater;
Context mContext;
Button del;
Plum1 plum;
Sms sms;
CheckBox isCheck;
// Can make custom Util class for user answer info
private List<Sms> mEntries = new ArrayList<Sms>();
public ListAdapter(Context context, LayoutInflater inflater,Plum1 plum) {
mLayoutInflater = (LayoutInflater) inflater;
this.plum=plum;
mContext = context;
}
@Override
public int getCount() {
return mEntries.size();
}
@Override
public Object getItem(int position) {
return mEntries.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(final int position, View convertView, final ViewGroup parent) {
if(convertView == null){
convertView = mLayoutInflater.inflate(R.layout.sms_layout, parent, false);
}
smsMsg = (TextView)convertView.findViewById(R.id.textViewForSMS);
isCheck = (CheckBox)convertView.findViewById(R.id.checkBox1);
// isCheck.setVisibility(View.VISIBLE);
smsMsg.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "long clicked", Toast.LENGTH_LONG).show();
//isCheck.setVisibility(View.INVISIBLE);
return false;
}
});
final Sms sms=mEntries.get(position);
smsMsg.setText(sms.getAddress()+" :\n "+sms.getMsg());
smsMsg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
plum.ShowSendMsgLayout(sms.getMsg().split(":")[0]);
}
});
smsMsg.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View arg0) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "deleted successfully", Toast.LENGTH_LONG).show();
return false;
}
});
return convertView;
}

public void upDateEntries(List<Sms> entries) {
mEntries.clear();
for(Sms sms : entries){
if(sms.getAddress().contains("PLUMSF")){
mEntries.add(sms);
}
}
notifyDataSetChanged();
}
}




Aucun commentaire:

Enregistrer un commentaire