Hi there I am facing issue when deleting row view from list. I just create a place order activity and there I register list and then create a class of cart Adapter.
When I delete the row it generates the exception can't delete the row. Is there any solution?
PlaceOrder.java
public class PlaceOrder extends Activity {
String [] pIds;
String [] pNames;
String [] pPrizes;
static ListView lv;
ImageView bck;
String [] listImages;
String food_id;
String userdata[];
Intent i;
Intent intent;
TextView totalprze;
float tprize;
ProgressDialog pDialog;
TableRow p_order;
AlertDialog.Builder builder;
List<String> cart=new ArrayList<String>();
String [] pId;
String [] PName;
String [] pPrize;
Intent intent_one;
String userid;
String status,message;
String [] delete;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_order);
lv=(ListView)findViewById(R.id.cart_list);
bck=(ImageView) findViewById(R.id.placeholder_bg_btn);
totalprze =(TextView) findViewById(R.id.place_order_price);
p_order=(TableRow)findViewById(R.id.p_order);
intent=new Intent(this,Food.class);
builder = new AlertDialog.Builder(this);
p_order.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(), "", Toast.LENGTH_LONG).show();
builder.setMessage(Html.fromHtml("<b>Place Order</b>"+"<br>Do you want to continue ?"))
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Cursor cursor = new ShopingCartHelper(PlaceOrder.this).getData(userid);
// Toast.makeText(getApplicationContext(), "View Cart",Toast.LENGTH_LONG).show();
if (cursor .moveToFirst()) {
while (cursor.isAfterLast() == false) {
String pid = cursor.getString(cursor
.getColumnIndex("id"));
String pName = cursor.getString(cursor
.getColumnIndex("product_name"));
String prize = cursor.getString(cursor
.getColumnIndex("price"));
cart.add(pid);
cart.add(pName);
// System.out.print("Product Name "+pName+"Price"+prize+"id"+id+"\n");
cart.add(prize);
cursor.moveToNext();
}
int length=cart.size();
pId=new String[cart.size()/3];
PName=new String[cart.size()/3];
pPrize=new String[cart.size()/3];
//System.out.print(length+"\n\n\n\n Values of List \n\n\n\n");
int k=0;
String[] values=cart.toArray(new String[cart.size()]);
// System.out.print("Values are :\n\n"+values);
int count=0;
for(int j=0;j<values.length/3;j++){
pId[j]=values[count];
count=count+1;
PName[j]=values[count];
count=count+1;
pPrize[j]=values[count];
count=count+1;
}
for(int i=0;i<pPrize.length;i++){
System.out.println(pPrize[i]);
}
}
// Toast.makeText(getApplicationContext(), "Yes",Toast.LENGTH_SHORT).show();
new place_order().execute();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}
);
AlertDialog d = builder.create();
// d.setTitle("Are you sure");
d.show();
TextView messageText = (TextView)d.findViewById(android.R.id.message);
messageText.setGravity(Gravity.CENTER);
}
});
i=new Intent(this,Menu.class);
bck.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle bundle=new Bundle();
//bundle.putStringArray("images", ListImages);
bundle.putString("food_id", food_id);
bundle.putStringArray("images", listImages);
bundle.putStringArray("userData",userdata);
i.putExtras(bundle);
startActivity(i);
}
});
if(this.getIntent().getExtras()!=null)
{
Bundle b=this.getIntent().getExtras();
pIds=b.getStringArray("pId");
pNames=b.getStringArray("PName");
pPrizes=b.getStringArray("pPrize");
userdata=b.getStringArray("userData");
tprize=b.getFloat("totalprize");
food_id=b.getString("food_id");
listImages=b.getStringArray("images");
String prz=Float.toString(tprize);
totalprze.setText("$"+prz);
delete=new String[pIds.length];
for(int m=0;m<pIds.length;m++){
delete[m]="Delete";
}
lv.setAdapter(new cartAdapter(PlaceOrder.this, pIds, pNames, pPrizes,userdata,delete));
userid=userdata[0];
pIds=null;
pNames=null;
pPrizes=null;
}
}
public void onBackPressed() {
pIds=null;
pNames=null;
pPrizes=null;
}
}
Cart Adapter.java
public class cartAdapter extends BaseAdapter{
String [] pIdz;
String [] pNamz;
String [] pPrizs;
String [] userData;
String [] del;
// List<String> imges;
Context context;
DrawerLayout dLayout;
// private ShopingCartHelper obj;
//ListView dList;
private static LayoutInflater inflater=null;
JSONArray jCat = null;
int count=0;
ProgressDialog pDialog;
public cartAdapter(PlaceOrder ctx,
String[] pIds,String[] pNams, String[] pprise,String [] userdata, String[] delete) {
pIdz=pIds;
pNamz=pNams;
context=ctx;
pPrizs=pprise;
userData=userdata;
del=delete;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
if(pIdz==null){
Toast.makeText(context, "There is issue with net connection.", Toast.LENGTH_LONG).show();
//Intent i=new Intent(context,WelcomeActivity.class);
//context.startActivity(i);
return count ;
}else{
return pIdz.length;
}
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class holder{
DrawerLayout dLayout;
TextView pid;
TextView pname;
TextView pprise;
Button delete;
ListView lv;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final holder hldr=new holder();
View rowView = null;
rowView = inflater.inflate(R.layout.place_order_item_list, null);
//hldr.dLayout= (DrawerLayout)rowView.findViewById(R.id.btn_drawer_layout);
// hldr.dLayout=(DrawerLayout)rowView.findViewById(R.id.btndrawerLayout);
hldr.pid=(TextView) rowView.findViewById(R.id.item_id);
hldr.pname=(TextView) rowView.findViewById(R.id.item_name);
hldr.pprise=(TextView) rowView.findViewById(R.id.item_price);
hldr.delete=(Button) rowView.findViewById(R.id.delete);
hldr.pid.setText(pIdz[position]);
hldr.pname.setText(pNamz[position]);
hldr.pprise.setText(pPrizs[position]);
hldr.delete.setText(del[position]);
hldr.delete.setTag(position);
hldr.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
int pid=Integer.parseInt(hldr.pid.getText().toString());
new ShopingCartHelper(context).delProduct(pid);
pIdz[position]=null;
pNamz[position]=null;
pPrizs[position]=null;
del[position]=null;
// new PlaceOrder().updateAdapter(context,pIdz,pNamz,pPrizs,del);
//
notifyDataSetChanged();
}
});
return rowView;
// TODO Auto-generated method stub
}
}
Your problem is in CartAdapter.java, you have:
pIdz[position]=null;
pNamz[position]=null;
pPrizs[position]=null;
del[position]=null;
You don't delete the item in list, you only set it to 'null' value. So when call 'notifyDataSetChanged' you made a NullPointerException.
To fix this bug, change all String[] to ArrayList, and easy call Java.util.ArrayList.remove(index)
As you want to remove the row from the list so you have to delete that explicitly for that you should declare Pidz like this
ArrayList<String> Pidz;
And in your cartAdapter constructor
Pidz = Arrays.asList(pIds);
Please modify your onclicklistener like this,
public void onClick(View v) {
int pid=Integer.parseInt(hldr.pid.getText().toString());
new ShopingCartHelper(context).delProduct(pid);
pIdz[position]=null;
pNamz[position]=null;
pPrizs[position]=null;
del[position]=null;
pIdz.remove(position);
notifyDataSetChanged();
}
});
Related
Hi I can not delete a row from list View i don't know how to delete it i search a lot from Internet i try out many examples but yet i can't solve the issue . when i click the hldr.delete button the complete row of list View delete from the list solution pls.
PlaceOrder Activity
public class PlaceOrder extends Activity {
String [] pIds;
String [] pNames;
String [] pPrizes;
static ListView lv;
ImageView bck;
String [] listImages;
String food_id;
String userdata[];
Intent i;
TextView totalprze;
float tprize;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_place_order);
lv=(ListView)findViewById(R.id.cart_list);
bck=(ImageView) findViewById(R.id.placeholder_bg_btn);
totalprze =(TextView) findViewById(R.id.place_order_price);
i=new Intent(this,Menu.class);
bck.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle bundle=new Bundle();
//bundle.putStringArray("images", ListImages);
bundle.putString("food_id", food_id);
bundle.putStringArray("images", listImages);
bundle.putStringArray("userData",userdata);
i.putExtras(bundle);
startActivity(i);
}
});
if(this.getIntent().getExtras()!=null)
{
Bundle b=this.getIntent().getExtras();
pIds=b.getStringArray("pId");
pNames=b.getStringArray("PName");
pPrizes=b.getStringArray("pPrize");
userdata=b.getStringArray("userData");
tprize=b.getFloat("totalprize");
food_id=b.getString("food_id");
listImages=b.getStringArray("images");
String prz=Float.toString(tprize);
totalprze.setText("$"+prz);
lv.setAdapter(new cartAdapter(PlaceOrder.this, pIds, pNames, pPrizes,userdata));
pIds=null;
pNames=null;
pPrizes=null;
}
}
public void onBackPressed() {
pIds=null;
pNames=null;
pPrizes=null;
}
}
CartAdapter
public class cartAdapter extends BaseAdapter{
String [] pIdz;
String [] pNamz;
String [] pPrizs;
String [] userData;
// List<String> imges;
Context context;
// private ShopingCartHelper obj;
private static LayoutInflater inflater=null;
JSONArray jCat = null;
int count=0;
ProgressDialog pDialog;
public cartAdapter(PlaceOrder ctx,
String[] pIds,String[] pNams, String[] pprise,String [] userdata) {
pIdz=pIds;
pNamz=pNams;
context=ctx;
pPrizs=pprise;
userData=userdata;
inflater = ( LayoutInflater )context.
getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
if(pIdz==null){
Toast.makeText(context, "There is issue with net connection.", Toast.LENGTH_LONG).show();
//Intent i=new Intent(context,WelcomeActivity.class);
//context.startActivity(i);
return count ;
}else{
return pIdz.length;
}
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public class holder{
TextView pid;
TextView pname;
TextView pprise;
Button delete;
ListView lv;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final holder hldr=new holder();
View rowView = null;
Bitmap bitmap = null;
rowView = inflater.inflate(R.layout.place_order_item_list, null);
hldr.pid=(TextView) rowView.findViewById(R.id.item_id);
hldr.pname=(TextView) rowView.findViewById(R.id.item_name);
hldr.pprise=(TextView) rowView.findViewById(R.id.item_price);
hldr.delete=(Button) rowView.findViewById(R.id.delete);
hldr.pid.setText(pIdz[position]);
hldr.pname.setText(pNamz[position]);
hldr.pprise.setText(pPrizs[position]);
/* convertView.setTag(hldr);
hldr.delete.setTag(hldr);*/
//
// Picasso.with(context).load(imgs[position]).into(hldr.img);
hldr.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
// rowView.remove(position); //removing from your List
//Toast.makeText(context, "Delete",Toast.LENGTH_LONG).show();
int pid=Integer.parseInt(hldr.pid.getText().toString());
//Toast.makeText(context, "pid"+pid, Toast.LENGTH_LONG).show();
new ShopingCartHelper(context).delProduct(pid);
//PlaceOrder.lv.removeViewAt(position);
notifyDataSetChanged();
}
});
rowView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// // TODO Auto-generated method stub
// cartAdapter.this.pIdz.remove[position];
// Toast.makeText(context, "hi",Toast.LENGTH_LONG).show();
}
});
return rowView;
// TODO Auto-generated method stub
}
}
You can't remove anything from an array - they're always fixed length. Once you've created an array of length 3, that array will always have length 3. And if you want to delete from the listview the array which you are used should be dynamic(Adding & Deleting). So make the pIdz; pNamz;pPrizs;userData into some Modal Object, and prepare the list of Modal Objects and pass it to adapter and make the life easier
You'd be better off with a List, e.g. an ArrayList:
hldr.delete.setTag(position);
hldr.delete.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
int position = (int)v.getTag();
list.remove(position);
notifyDataSetChanged();
}
});
First.
You should make a object that stores all your different strings instead of using multiple arrays for each value.
Ej:
class MyClass
{
String id;
String name
String price;
public MyClass(String id, String name, String price)
{
this.id = id;
this.name = name;
this.price = price;
}
}
That way you wouldnt have to delete the position of each of the arrays.
And finally to answer your question, just delete the value of position you want to delete for each of the arrays.
Since they are Array and not ArrayList you will need to recreate it with the correct new dimension (Note it will be much easier with ArrayList).
Then just call notifyDataSetChanged() on your Adapter class.
Hope this helps.
I just want to get the value of clicked list item,
i.e if list contains apple,ball,cat, then clicked on apple then it gives value as apple, ,In the below code I am using inner class base adapter to display the data.
public class RecordsActivity extends Activity implements
OnItemClickListener
{
ListView listProduct;
ListAdapter adapter;
TextView UserName,Date;
ArrayList<String> billDate = new ArrayList<String>();
ArrayList<String> billNo = new ArrayList<String>();
ArrayList<String >partyName=new ArrayList<String>();
ArrayList<String> billAmount = new ArrayList<String>();
ArrayList<String >receipt=new ArrayList<String>();
ArrayList<String >balance=new ArrayList<String>();
ArrayList<String> week = new ArrayList<String>();
ArrayList<String> amount = new ArrayList<String>();
String get_name,get_date,Name;
String GetAmnt;
Dialog dialog;
AlertDialog alertDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_records);
UserName=(TextView) findViewById(R.id.txt_disuser);
Intent usr=getIntent();
get_name=usr.getStringExtra("user");
UserName.setText(get_name);
Date=(TextView) findViewById(R.id.txt_disdate);
Intent dt=getIntent();
get_date=dt.getStringExtra("date");
Date.setText(get_date);
Intent id =getIntent();
Name=id.getStringExtra("name");
listProduct=(ListView) findViewById(R.id.ListViewFilledRecrd);
listProduct.setAdapter(adapter);
/*listProduct.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3)
{
listProduct.setClickable(true);
String data = (String)listProduct.getItemAtPosition(arg2);
Toast.makeText(getApplicationContext(),data,
Toast.LENGTH_SHORT).show();
}
});*/
}
protected void onResume()
{
getAllProduct();
super.onResume();
}
public void getAllProduct(){
SQLiteDatabase db = this.getDB();
Cursor c;
//c=db.rawQuery("SELECT * FROM RECORDS", null);
c=db.rawQuery("SELECT * FROM RECORDS WHERE PARTY_NAME = '" + Name +
"' ", null);
String
BILL_DATE,BILL_NO,PARTY_NAME,BILL_AMOUNT,RECEIPT,BALANCE,WEEK,AMOUNT;
if(c.moveToFirst())
{
do
{
BILL_DATE = c.getString(1);
BILL_NO=c.getString(2);
PARTY_NAME=c.getString(3);
BILL_AMOUNT=c.getString(4);
RECEIPT=c.getString(5);
BALANCE=c.getString(6);
WEEK=c.getString(7);
AMOUNT=c.getString(8);
billDate.add(BILL_DATE);
billNo.add(BILL_NO);
partyName.add(PARTY_NAME);
billAmount.add(BILL_AMOUNT);
receipt.add("RECEIPT");
balance.add(BALANCE);
week.add(WEEK);
amount.add(AMOUNT);
} while (c.moveToNext());
}
DisplyRecords dsptProd=new
DisplyRecords(RecordsActivity.this,billDate,billNo,partyName,
billAmount,receipt,balance,week,amount);
listProduct.setAdapter(dsptProd);
listProduct.setOnItemClickListener(this);
c.close();
db.close();
}
private SQLiteDatabase getDB()
{
String DB_NAME = "odsr.db";
return openOrCreateDatabase(DB_NAME, SQLiteDatabase.OPEN_READWRITE,
null);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
}
}
class DisplyRecords extends BaseAdapter
{
Context c;
ArrayList<String > BILLDATE;
ArrayList<String>BILLNO;
ArrayList<String> PARTYNAME;
ArrayList<String>BILLAMOUNT;
ArrayList<String>RECEIPT;
ArrayList<String> BALANCE;
ArrayList<String>WEEK;
ArrayList<String>AMOUNT;
public DisplyRecords(RecordsActivity recordsactivity,ArrayList<String>
billDate, ArrayList<String> billNo, ArrayList<String>
partyName,ArrayList<String> billAmount, ArrayList<String> receipt,
ArrayList<String> balance, ArrayList<String> week,ArrayList<String> amount)
{
this.c=recordsactivity;
this.BILLDATE=billDate;
this.BILLNO=billNo;
this.PARTYNAME=partyName;
this.BILLAMOUNT=billAmount;
this.RECEIPT=receipt;
this.BALANCE=balance;
this.WEEK=week;
this.AMOUNT=amount;
//TODO Auto-generated constructor stub
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return BILLDATE.size();
}
#Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
#Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(final int pos, View row, ViewGroup parent)
{
View child=row;
LayoutInflater layoutinflater;
if(child==null)
{
layoutinflater=(LayoutInflater)
c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutinflater.inflate(R.layout.list_product,null);
}
TextView txt_billdate=(TextView) child.findViewById(R.id.txt_bill_date);
TextView txt_billno=(TextView) child.findViewById(R.id.txt_bill_no);
TextView txt_partyname=(TextView)
child.findViewById(R.id.txt_party_name);
TextView txt_billamt=(TextView)
child.findViewById(R.id.txt_bill_amount);
TextView txt_receipt=(TextView) child.findViewById(R.id.txt_receipt);
TextView txt_balance=(TextView) child.findViewById(R.id.txt_balance);
TextView txt_wk=(TextView) child.findViewById(R.id.txt_week);
TextView txt_amount=(TextView) child.findViewById(R.id.txt_amount);
txt_billdate.setText(BILLDATE.get(pos));
txt_billno.setText(BILLNO.get(pos));
txt_partyname.setText(PARTYNAME.get(pos));
txt_billamt.setText(BILLAMOUNT.get(pos));
txt_receipt.setText(RECEIPT.get(pos));
txt_balance.setText(BALANCE.get(pos));
txt_wk.setText(WEEK.get(pos));
txt_amount.setText(AMOUNT.get(pos));
// TODO Auto-generated method stub
return child;
}
}
A few assumptions here, your actual fields do not need to be ArrayList's since each query returns a single row item from the db, i create a master object with Strings to represent the data...
So here is how i would do it, you need to re structure your data
First i would change your data to a :
public class ParentObject {
public String BILLDATE ;
public String BILLNO ;
public String PARTYNAME ;
public String BILLAMOUNT ;
public String RECEIPT ;
public String BALANCE ;
public String WEEK ;
public String AMOUNT ;
}
UPDATE
then i would change my Activity to:
public class RecordsActivity extends Activity implements OnItemClickListener{
ListView listProduct;
ListAdapter adapter;
TextView UserName,Date;
// your new parent object ArrayList, much cleaner
List<ParentObject> parentObjects;
String get_name,get_date,Name;
String GetAmnt;
Dialog dialog;
AlertDialog alertDialog;
#Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_records);
UserName=(TextView) findViewById(R.id.txt_disuser);
Intent usr=getIntent();
get_name=usr.getStringExtra("user");
UserName.setText(get_name);
Date=(TextView) findViewById(R.id.txt_disdate);
Intent dt=getIntent();
get_date=dt.getStringExtra("date");
Date.setText(get_date);
Intent id =getIntent();
Name=id.getStringExtra("name");
listProduct=(ListView) findViewById(R.id.ListViewFilledRecrd);
listProduct.setAdapter(adapter);
listProduct.setOnItemClickListener(this);
}
protected void onResume(){
getAllProduct();
super.onResume();
}
public void getAllProduct(){
SQLiteDatabase db = this.getDB();
Cursor c;
//c=db.rawQuery("SELECT * FROM RECORDS", null);
c=db.rawQuery("SELECT * FROM RECORDS WHERE PARTY_NAME = '" + Name + "' ", null);
String BILL_DATE,BILL_NO,PARTY_NAME,BILL_AMOUNT,RECEIPT,BALANCE,WEEK,AMOUNT;
if(c.moveToFirst()){
// initialize the parent arrayList
parentObjects = new ArrayList<ParentObject>();
do{
// initialize a single object
ParentObject parentObject = new ParentObject();
// fill in its data
parentObject.BILL_DATE = c.getString(1);
parentObject.BILL_NO=c.getString(2);
parentObject.PARTY_NAME=c.getString(3);
parentObject.BILL_AMOUNT=c.getString(4);
parentObject.RECEIPT=c.getString(5);
parentObject.BALANCE=c.getString(6);
parentObject.WEEK=c.getString(7);
parentObject.AMOUNT=c.getString(8);
// add it to your list
parentObjects.add(parentObject);
} while (c.moveToNext());
}
// pass the List<ParentObject> into your adapter
DisplyRecords dsptProd= new DisplyRecords(RecordsActivity.this, (ArrayList<ParentObject>)parentObjects);
listProduct.setAdapter(dsptProd);
listProduct.setOnItemClickListener(this);
c.close();
db.close();
}
private SQLiteDatabase getDB(){
String DB_NAME = "odsr.db";
return openOrCreateDatabase(DB_NAME, SQLiteDatabase.OPEN_READWRITE,
null);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
// access to all your data through the parentObject
ParentObject data = (ParentObject) listProduct.getItemAtPosition(position);
// access all fields for this parent
Toast.makeText(RecordsActivity.this, "data: "+ data.BILL_DATE, + " ," + data.BILL_NO, " , etc", Toast.LENGTH_LONG).show();
}
}
and then update your Adapter to handle the List
class DisplyRecords extends BaseAdapter {
Context c;
List<ParentObject> parentObjects;
public DisplyRecords(Context context, ArrayList<ParentObject> parentObjects){
this.c=context;
this.parentObjects = parentObjects;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return parentObjects.size();
}
#Override
public Object getItem(int position) {
return parentObjects.get(position); // always return this parent
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(final int pos, View row, ViewGroup parent){
// You should implement the ViewHolder pattern, this is not doing that...
View child=row;
LayoutInflater layoutinflater;
if(child==null){
layoutinflater=(LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutinflater.inflate(R.layout.list_product,null);
}
TextView txt_billdate=(TextView) child.findViewById(R.id.txt_bill_date);
TextView txt_billno=(TextView) child.findViewById(R.id.txt_bill_no);
TextView txt_partyname=(TextView) child.findViewById(R.id.txt_party_name);
TextView txt_billamt=(TextView) child.findViewById(R.id.txt_bill_amount);
TextView txt_receipt=(TextView) child.findViewById(R.id.txt_receipt);
TextView txt_balance=(TextView) child.findViewById(R.id.txt_balance);
TextView txt_wk=(TextView) child.findViewById(R.id.txt_week);
TextView txt_amount=(TextView) child.findViewById(R.id.txt_amount);
ParentObject parentObject = parentObjects.get(pos);
txt_billdate.setText(parentObject.BILLDATE);
txt_billno.setText(parentObject.BILLNO.);
txt_partyname.setText(parentObject.PARTYNAME);
txt_billamt.setText(parentObject.BILLAMOUNT);
txt_receipt.setText(parentObject.RECEIPT);
txt_balance.setText(parentObject.BALANCE);
txt_wk.setText(parentObject.WEEK);
txt_amount.setText(parentObject.AMOUNT);
// TODO Auto-generated method stub
return child;
}
}
i am calling a web service to get some details and show them in a list view.now i have to show a image on that list view. i can retrieve the image url from JSON object. but when the image url contains null , i want to show a defult image in the list view. i know below code is the code segment which is use to that.but since im going to handle this inside of my adapter class (extends by BaseAdapter Class) i cant use it.. please guide me how to handle this...
here my Adapter class
public class NewsRowAdapter extends BaseAdapter {
static Dialog dialogs;
private static final String STIME = "StartTime";
private static final String END = "EndTime";
private static final String DATE = "Date";
private Context mContext;
private Activity activity;
private static LayoutInflater inflater=null;
private ArrayList<HashMap<String, String>> data;
int resource;
public ImageLoader imageLoader;
//String response;
//Context context;
//Initialize adapter
public NewsRowAdapter(Context ctx,Activity act, int resource,ArrayList<HashMap<String, String>> d) {
super();
this.resource=resource;
this.data = d;
this.activity = act;
this.mContext = ctx;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
}
public void showFirstDialog(final ArrayList<HashMap<String, String>> list){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
alertDialogBuilder.setTitle("Confirm your Action!");
// set dialog message
alertDialogBuilder
.setMessage("You Have Similar Kind of Appoinments!! Do you wanna Show them ?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
Toast.makeText(mContext, "Showing", Toast.LENGTH_LONG).show();
dialogpop(list);
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
alertDialogBuilder.show();
}
public void dialogshow(final String Date,final String Start,final String End){
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
alertDialogBuilder.setTitle("Confirm your Action!");
// set dialog message
alertDialogBuilder
.setMessage("Click yes Confirm!!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
//MainActivity.this.finish();
Toast.makeText(mContext, "Yes clicked", Toast.LENGTH_LONG).show();
//check similer records
//if duplicates > 1 then show the popup list
//if(duplicateList.size()>1){
/*final Dialog dialogs = new Dialog(activity);
dialogs.setContentView(R.layout.dialog_list);
dialogs.setTitle("Select One");
ListView listView = (ListView) dialogs.findViewById(R.id.dialogList);
NewsRowAdapter nw = new NewsRowAdapter(mContext, activity, R.layout.dialog_row, duplicateList);
listView.setAdapter(nw);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0,
View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
dialogs.dismiss();
}
});
dialogs.show();*/
// }
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
alertDialogBuilder.show();
}
public void showDuplicateDialog(ArrayList<HashMap<String, String>> list){
//CharSequence[] cs = list.toArray(new CharSequence[list.size()]);
AlertDialog.Builder alertDialogBuilder2 = new AlertDialog.Builder(activity);
LayoutInflater infl = activity.getLayoutInflater();
View view = infl.inflate(R.layout.dialog_list, null);
ListView lv = (ListView) view.findViewById(R.id.dialogList);
//NewsRowAdapter nw = new NewsRowAdapter(mContext, activity, R.layout.dialog_row, list);
SimpleAdapter sim = new SimpleAdapter(mContext, list, R.layout.dialog_row, new String[] { STIME,END, DATE }, new int[] {
R.id.stime2,R.id.etime2, R.id.blank2});
lv.setAdapter(sim);
lv.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "item clicked ", Toast.LENGTH_LONG).show();
}
});
/*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.two_line_list_item, android.R.id.text1, Names);*/
alertDialogBuilder2.setView(view)
/*alertDialogBuilder2.setAdapter(sim, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "item clicked ", Toast.LENGTH_LONG).show();
}
})
*/
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
Toast.makeText(mContext, "Accepted", Toast.LENGTH_LONG).show();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
alertDialogBuilder2.show();
}
#Override
public View getView(final int position, View convertView, final ViewGroup parent) {
View vi = convertView;
if(convertView==null)
vi = inflater.inflate(R.layout.row,null);
final TextView firstname = (TextView) vi.findViewById(R.id.fname);
final TextView lastname = (TextView) vi.findViewById(R.id.lname);
final TextView startTime = (TextView) vi.findViewById(R.id.stime);
final TextView endTime = (TextView) vi.findViewById(R.id.etime);
final TextView date = (TextView) vi.findViewById(R.id.blank);
final TextView hidID = (TextView) vi.findViewById(R.id.hidenID);
final ImageView img = (ImageView) vi.findViewById(R.id.list_image);
HashMap<String, String> song = new HashMap<String, String>();
song =data.get(position);
firstname.setText(song.get(MainActivity.TAG_PROP_FNAME));
lastname.setText(song.get(MainActivity.TAG_PROP_LNAME));
startTime.setText(song.get(MainActivity.TAG_STIME));
endTime.setText(song.get(MainActivity.TAG_ETIME));
date.setText(song.get(MainActivity.TAG_DATE));
hidID.setText(song.get(MainActivity.TAG_HID));
String theUrl = song.get(MainActivity.TAG_IMG);
if(theUrl.equalsIgnoreCase("null")){
/*Bitmap bImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.propic);
profPic.setImageBitmap(bImage);
ViewList v = new ViewList();
v.handleImage(theUrl, img);*/
}
else{
imageLoader.DisplayImage(song.get(MainActivity.TAG_IMG), img);
}
Button accept = (Button) vi.findViewById(R.id.btnAccepted);
accept.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
final int x = (int) getItemId(position);
/*Intent zoom=new Intent(mContext, Profile.class);
zoom.setFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
zoom.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mContext.startActivity(zoom);*/
// get the intent from the hashmap check if there is similar date and time.
//then store them in a list or array.
String getDate = (String) date.getText();
String getStartTime = startTime.getText().toString();
String getEndTime = endTime.getText().toString();
ShortList sh = new ShortList();
ArrayList<HashMap<String, String>> duplicateList;
duplicateList=sh.getDuplicated(getDate, getStartTime, getEndTime);
if(duplicateList.size()>1){
//dialogshow(getDate,getStartTime,getEndTime);
showFirstDialog(duplicateList);
}
else{
dialogshow(getDate, getStartTime, getEndTime);
}
}
});
vi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
String getPname = hidID.getText().toString();
Toast.makeText(parent.getContext(), "view clicked: "+getPname , Toast.LENGTH_SHORT).show();
//get the id of the view
//check the id of the request
//call the web service acording to the id
Intent zoom=new Intent(parent.getContext(), Profile.class);
zoom.putExtra("PatientID", getPname);
parent.getContext().startActivity(zoom);
}
});
return vi;
}
public void dialogpop(ArrayList<HashMap<String, String>> list){
dialogs = new Dialog(activity);
dialogs.setContentView(R.layout.dialog_list);
dialogs.setTitle("Select One");
ListView listView = (ListView) dialogs.findViewById(R.id.dialogList);
//SimpleAdapter sim = new SimpleAdapter(mContext, list, R.layout.dialog_row, new String[] { STIME,END, DATE }, new int[] {
// R.id.stime2,R.id.etime2, R.id.blank2});
Adapter_For_Dialog nw = new Adapter_For_Dialog(mContext,activity, R.layout.dialog_row, list);
listView.setAdapter(nw);
dialogs.show();
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
#Override
public Object getItem(int possision) {
// TODO Auto-generated method stub
return possision;
}
#Override
public long getItemId(int possision) {
// TODO Auto-generated method stub
return possision;
}
}
please help me :)
My problem is i cant use this code segment in my adapter Class
Bitmap bImage = BitmapFactory.decodeResource(this.getResources(), R.drawable.propic);
profPic.setImageBitmap(bImage);
Replace
if(theUrl.equalsIgnoreCase("null")){
with
if(theUrl==null || theUrl.equals("")){
and check if it works or not
I have a custom baseadapter that creates comment boxes. Everything works great on it until I want to add data. When I try to add the data it deletes the previous data and adds the new data. How do I make it so it keeps all the data? Is my Add method incorrect? Here is my baseadapter,
class CreateCommentLists extends BaseAdapter{
Context ctx_invitation;
String[] listComments;
String[] listNumbers;
String[] listUsernames;
public CreateCommentLists(String[] comments, String[] usernames, String[] numbers, DashboardActivity context)
{
super();
ctx_invitation = context;
listComments = comments;
listNumbers = usernames;
listUsernames = numbers;
}
#Override
public int getCount() {
if(null == listComments)
{
return 0;
}
// TODO Auto-generated method stub
return listComments.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return listComments[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = null;
try
{
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)ctx_invitation.getSystemService(inflater);
v = li.inflate(R.layout.list_item, null);
TextView commentView = (TextView)v.findViewById(R.id.listComment);
TextView NumbersView = (TextView)v.findViewById(R.id.listNumber);
TextView usernamesView = (TextView)v.findViewById(R.id.listPostedBy);
Button usernameButton = (Button)v.findViewById(R.id.listUsernameButton);
Button numberButton = (Button)v.findViewById(R.id.listNumberButton);
commentView.setText(listComments[position]);
NumbersView.setText(listNumbers[position]);
usernamesView.setText(listUsernames[position]);
usernameButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), ProfileActivity.class);
i.putExtra("usernameOfProfile",listUsernames[position]);
startActivity(i);
finish();
}
});
numberButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(getApplicationContext(), ProfileActivity.class);
i.putExtra("NumberProfile",listNumbers[position]);
startActivity(i);
finish();
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
return v;
}
public void add(String[] comments, String[] usernames,
String[] numbers) {
listComments = comments;
listNumbers = usernames;
listUsernames = numbers;
}
public int getCount1() {
if(null == listComments)
{
return 0;
}
// TODO Auto-generated method stub
return listComments.length;
}
public Object getItem1(int position) {
// TODO Auto-generated method stub
return listComments[position];
}
public long getItemId1(int position) {
// TODO Auto-generated method stub
return 0;
}
public View getView1(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = null;
try
{
String inflater = Context.LAYOUT_INFLATER_SERVICE;
LayoutInflater li = (LayoutInflater)ctx_invitation.getSystemService(inflater);
v = li.inflate(R.layout.list_item, null);
TextView commentView = (TextView)v.findViewById(R.id.listComment);
TextView NumbersView = (TextView)v.findViewById(R.id.listNumber);
TextView usernamesView = (TextView)v.findViewById(R.id.listPostedBy);
Button usernameButton = (Button)v.findViewById(R.id.listUsernameButton);
Button numberButton = (Button)v.findViewById(R.id.listNumberButton);
commentView.setText(listComments[position]);
NumbersView.setText(listNumbers[position]);
usernamesView.setText(listUsernames[position]);
usernameButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(), ProfileActivity.class);
i.putExtra("usernameOfProfile",listUsernames[position]);
startActivity(i);
finish();
}
});
numberButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent i = new Intent(getApplicationContext(), ProfileActivity.class);
i.putExtra("NumberProfile",listNumbers[position]);
startActivity(i);
finish();
}
});
}
catch(Exception e)
{
e.printStackTrace();
}
return v;
}
}
Setting the adapter:
final CreateCommentLists mycmlist = new CreateCommentLists(comments, usernames, numbers, DashboardActivity.this);
lstComments = (ListView)findViewById(android.R.id.list);
lstComments.setAdapter(mycmlist);
This is what how I call the add method,
mycmlist.add(comments,usernames,numbers);
mycmlist.notifyDataSetChanged();
In your add method you're setting the arrays to new values listComments = comments; That's replacing your old data with the new data.
You could use System.arrayCopy() to resize your listArrays to the new size and append the new items. A much less tedious approach, however, would be to store your arrays as List<String>, allowing you to add more items without worrying about resizing lists.
The result would look something like this...
public class CommentsAdapter extends BaseAdapter
{
private LayoutInflater inflater;
private List<String> comments;
private List<String> numbers;
private List<String> usernames;
public CommentsAdapter(Context context)
{
inflater = LayoutInflater.from(context);
comments = new ArrayList<String>();
numbers = new ArrayList<String>();
usernames = new ArrayList<String>();
}
public void add(String[] comments, String[] numbers, String[] usernames)
{
this.comments.addAll(Arrays.asList(comments));
this.numbers.addAll(Arrays.asList(numbers));
this.usernames.addAll(Arrays.asList(usernames));
notifyDataSetChanged();
}
#Override
public int getCount()
{
if (comments == null)
return 0;
return comments.size();
}
#Override
public String getItem(int position)
{
return comments.get(position);
}
#Override
public long getItemId(int position)
{
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent)
{
if (convertView == null)
{
convertView = inflater.inflate(R.layout.list_item, parent, false);
convertView.setTag(new ViewHolder(convertView));
}
ViewHolder holder = (ViewHolder) convertView.getTag();
holder.commentView.setText(comments.get(position));
//Other view bind logic here...
return convertView;
}
private static class ViewHolder
{
public TextView commentView;
public TextView numbersView;
public TextView usernamesView;
public Button usernameButton;
public Button numberButton;
public ViewHolder(View v)
{
commentView = (TextView) v.findViewById(R.id.listComment);
numbersView = (TextView) v.findViewById(R.id.listNumber);
usernamesView = (TextView) v.findViewById(R.id.listPostedBy);
usernameButton = (Button) v.findViewById(R.id.listUsernameButton);
numberButton = (Button) v.findViewById(R.id.listNumberButton);
}
}
}
I also highly recommend reading this page on the Android Developer's site: http://developer.android.com/training/improving-layouts/smooth-scrolling.html
Your current adapter implementation is very inefficient, and that page should help you iron out some kinks.
You probably need to add the String[] array to the existing one, instead of replacing it.
Add this function which joins two arrays (Sadly there is no already-implemented method for Java):
String[] concat(String[] A, String[] B) {
String[] C= new String[A.length + B.length];
System.arraycopy(A, 0, C, 0, A.length);
System.arraycopy(B, 0, C, A.length, B.length);
return C;
}
Credits: Sun Forum
And then change the add method to this:
public void add(String[] comments, String[] usernames,
String[] numbers) {
listComments = concat(listComments, comments);
listUsernames = concat(listUsernames, usernames);
listNumbers = concat(listNumbers, numbers);
}
And you had a typo in your code. In the add method, the listUsernames and listNumbers should be swapped I think.. I fixed it for you.
I have an application with three textviews and one checkbox in each row of a listview.what I want that on a click of a button I will be able to get the state of each checkbox and the row corresponding to (isChecked) checkboxes get deleted.one more thing my checkboxes are hardcoded in an xml file.I have searched a lot but couldn't find anything specific.thanks in advance.HERE IS MY CODE...
public class recentcalllistultimate extends ListActivity implements OnClickListener {
CheckBox cb;
Button edit,done;
ImageButton contacts;
ListView lv;
ListView lvultimate;
listviewadapterultimate lvar;
int[] uniqueid;
String[] names;
String[] types;
;
RelativeLayout rl;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
LayoutParams params=newRelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
LinearLayout mainLayout = new LinearLayout(this);
mainLayout.setOrientation(LinearLayout.VERTICAL);
LayoutInflater layoutInflater = getLayoutInflater();
mainLayout.addView(layoutInflater.inflate(R.layout.listviewonly, null));
mainLayout.addView(layoutInflater.inflate(R.layout.allbuttons, null));
this.addContentView(mainLayout, params);
cb = (CheckBox) findViewById(R.id.checkboxdelete);
getContacts();
lv = (ListView) findViewById(android.R.id.list);
lvar = new listviewadapterultimate(this, names, types,uniqueid);
lv.setAdapter(lvar);
contacts = (ImageButton) findViewById(R.id.button_keypad);
contacts.setOnClickListener(this);
edit = (Button) findViewById(R.id.editbutton);
done=(Button)findViewById(R.id.donebutton);
done.setOnClickListener(new View.OnClickListener() {
------>>> public void onClick(View v) {
// TODO Auto-generated method stub
cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, booleanisChecked) {
// TODO Auto-generated method stub
//WHAT TO DO HERE....
}
}
});
}
------>>> });
edit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
AddDialog ada=new AddDialog(recentcalllistultimate.this);
ada.show();
}
});
}// on create
public void getContacts() {
ContentResolver cr = getContentResolver();
Cursor cur = cr.query(android.provider.CallLog.Calls.CONTENT_URI, null,
null, null, null);
if (cur.getCount() > 0) {
int i = 0;
int foo = 0;
names = new String[cur.getCount()];
types = new String[cur.getCount()];
duration = new long[cur.getCount()];
uniqueid = new int[cur.getCount()];
int n = cur.getColumnIndex(CallLog.Calls._ID);
int k = cur.getColumnIndex(CallLog.Calls.CACHED_NAME);
int y = cur.getColumnIndex(CallLog.Calls.NUMBER);
int z = cur.getColumnIndex(CallLog.Calls.CACHED_NUMBER_TYPE);
while (cur.moveToNext()) {
uniqueid[foo] = cur.getInt(n);
String str = cur.getString(k);
if (str == null) {
names[foo] = cur.getString(y);
}// if
else {
names[foo] = str;
}
int temp = cur.getInt(z);
switch (temp) {
case 0:
types[foo] = "unknown";
break;
case 1:
types[foo] = "home";
break;
case 2:
types[foo] = "mobile";
break;
case 3:
types[foo] = "work";
break;
}// switch
long doo = cur.getInt(d);
duration[foo] = doo;
foo++;
} // while
}// if
}//getcontacts
public void onClick(View v) {
// TODO Auto-generated method stub
if(v==contacts){
Intent intent = new Intent();
intent.setClassName("com.a.Activities",
"com.a.Activities.DialPad");
startActivity(intent);
finish();
}
}
}// class
.................................
public class listviewadapterultimate extends BaseAdapter {
viewHolder holder;
Activity context;
String[] names;
String[] types;
String[] duration;
int[] uniqueid;
public listviewadapterultimate(Activity context, String[] names,
String[] types, int[] uniqueid2 ) {
this.context = context;
this.names = names;
this.types = types;
uniqueid=uniqueid2;
}
public int getCount() {
// TODO Auto-generated method stub
return names.length;
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
public class viewHolder {
TextView top;
TextView bottom;
TextView down;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
if (convertView == null) {
holder = new viewHolder();
LayoutInflater inflator = context.getLayoutInflater();
convertView = inflator.inflate(R.layout.recenttextviewonlyultimate, null);
holder.top = (TextView) convertView.findViewById(R.id.toptext_u);
holder.bottom = (TextView) convertView
.findViewById(R.id.bottomtext_u);
holder.down = (TextView) convertView.findViewById(R.id.recentuniqueid_u);
convertView.setTag(holder);
} else {
holder = (viewHolder) convertView.getTag();
//holder.cb.setVisibility(View.VISIBLE);
}
holder.top.setText(names[position]);
holder.bottom.setText(types[position]);
holder.down.setText("" + uniqueid[position]);
return convertView;
}
}
................
Try this:
Inside your getView(...) method...
final CheckBox lChk = ((CheckBox) pConvertView.findViewById(R.id.myChkBoxID));
private List<lisInfo> m_lisInfo = new ArrayList<lisInfo>();
lChk.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Populate the listInfo with check box status
m_lisInfo.get(lPosition).setChkBoxStatus((isChecked));
}
});
public class lisInfo{
private boolean chkBoxStatus;
public boolean isChkBoxStatus() {
return chkBoxStatus;
}
public void setChkBoxStatus(boolean chkBoxStatus) {
this.chkBoxStatus = chkBoxStatus;
}
}
Now iterate the listInfo wherever required to get the check boxes statuses in the list view
maintain an array of boolean inside adapter . set listener on ckeckbox in getview which will swipe values of array on check/uncheck .
now make this array accesible in activity where on button
click()
{
for(int i=0;i<array.size;i++)
{
if(array[i])
adapter.deelet(item i);
//modify syntax
}
}