0
我正在使用ListView從數據庫中獲取數據。 當我打電話更新和刪除我刷新活動通過呼籲Intent
。 它顯示更新列表,但是當我點擊它時,它不顯示文本視圖中我顯示列表詳細信息的更改。 我使用自定義Adapter.Below是我的代碼,要更新項目單擊後更改列表視圖
public class Mainmenu extends Activity{
ListView list;
DBHandler db= new DBHandler(this);
int ID;
String strname,strlastname,strdob,strcell,strcnic,straddress;
String pppath,cfpath,cbpath,fppath;
TextView tvname,tvlastname,tvdob,tvcnic,tvcell,tvaddress;
ImageView pp,cf,cb;
public static ArrayList<String> customers = new ArrayList<String>();
SearchResults sr1;
ArrayList<SearchResults> searchResults= new ArrayList<SearchResults>();
MyCustomBaseAdapter adaptor;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenulist);
list= (ListView) findViewById(R.id.listMM);
tvname=(TextView)findViewById(R.id.textView3);
tvlastname=(TextView)findViewById(R.id.textView4);
tvdob=(TextView)findViewById(R.id.textView5);
tvcnic=(TextView)findViewById(R.id.textView10);
tvcell=(TextView)findViewById(R.id.textView7);
tvaddress=(TextView)findViewById(R.id.textView8);
pp=(ImageView)findViewById(R.id.ImageView02);
cf=(ImageView)findViewById(R.id.imageView2);
cb=(ImageView)findViewById(R.id.ImageView03);
Context c =getApplicationContext();
if(db.getAllcustomers2().toString()==null){
db.getWritableDatabase();
db.init();
}else{
List<Customers_GS> gtEdu = db.getAllcustomers2();
customers.clear();
for (Customers_GS ed : gtEdu) {
sr1 = new SearchResults();
ID=ed.getCID();
sr1.setId(ID);
customers.add(ed.getCustomer_Name());
strname=ed.getCustomer_Name().toString();
sr1.setName(strname);
customers.add(ed.getCustomer_DOB());
strdob=ed.getCustomer_DOB().toString();
sr1.setDOB(strdob);
customers.add(ed.getCustomer_CNIC());
strcnic=ed.getCustomer_CNIC().toString();
sr1.setCNIC(strcnic);
customers.add(ed.getCustomer_Cell());
strcell=ed.getCustomer_Cell().toString();
sr1.setPhone(strcell);
customers.add(straddress);
straddress=ed.getCustomer_Address().toString();
sr1.setAddress(straddress);
customers.add(ed.getCustomer_PP());
pppath=ed.getCustomer_PP().toString();
customers.add(ed.getCustomer_CNICf());
cfpath=ed.getCustomer_CNICf().toString();
customers.add(ed.getCustomer_CNICb());
cbpath=ed.getCustomer_CNICb().toString();
customers.add(ed.getCustomer_Thumb());
sr1.setImageNumber(1);
searchResults.add(sr1);
}
}
adaptor= new MyCustomBaseAdapter(c, searchResults);
list.setAdapter(adaptor);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
int height= 146;
int width=146;
//parent.getItemAtPosition(position);
//
Log.d("PP", ""+pppath);
Log.d("cP", ""+cbpath);
Log.d("fP", ""+cfpath);
// Bitmap ppbitmap = BitmapFactory.decodeFile(pppath);
// Bitmap cbbitmap = BitmapFactory.decodeFile(cbpath);
// Bitmap cfbitmap = BitmapFactory.decodeFile(cfpath);
// ppbitmap=Bitmap.createScaledBitmap(ppbitmap, width,height, true);
// cbbitmap=Bitmap.createScaledBitmap(cbbitmap, width,height, true);
// cfbitmap=Bitmap.createScaledBitmap(cfbitmap, width,height, true);
//
// pp.setImageBitmap(ppbitmap);
// cb.setImageBitmap(cbbitmap);
// cf.setImageBitmap(cfbitmap);
String[] result =strname.split(" ");
strname= result[0];
strlastname=result[1];
tvname.setText(strname);
tvlastname.setText(strlastname);
tvcell.setText(strcell);
tvaddress.setText(straddress);
tvcnic.setText(strcnic);
tvdob.setText(strdob);
adaptor.notifyDataSetChanged();
}
});
list.setOnItemLongClickListener(new OnItemLongClickListener() {
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int pos, long id) {
// // TODO Auto-generated method stub
//
//
db.getWritableDatabase();
// db.delete(ID);
// db.update(17);
// // TODO Auto-generated method stub
//
// Intent gonext= new Intent("com.example.ibex.MAINMENU");
// startActivity(gonext);
//
AlertDialog.Builder builder = new AlertDialog.Builder(Mainmenu.this);
builder.setMessage("Chose any one!");
builder.setCancelable(false);
builder.setPositiveButton("Edit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.update(ID);
Intent reload = new Intent(getApplicationContext(), Mainmenu.class);
startActivity(reload);
}
});
builder.setNegativeButton("Delete", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
db.delete(ID);
Intent reload = new Intent(getApplicationContext(), Mainmenu.class);
startActivity(reload);
}
});
AlertDialog alert = builder.create();
alert.show();
return true;
}
});
}
////### ## ##### ### ### ### ### #### ### ### ### ### ### ## ////
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.optionmenu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.getItemId()==R.id.Addmenu){
Intent openstngs=new Intent("com.example.ibex.REGISTRATION");
startActivity(openstngs);
}else if(item.getItemId()==R.id.Edithmenu){
Bundle contan= new Bundle();
contan.putInt("key", ID);
Intent web =new Intent(Mainmenu.this, Edit.class);
web.putExtras(contan);
startActivity(web);
}else if(item.getItemId()==R.id.Dltmenu){
db.delete(ID);
Intent reload = new Intent(getApplicationContext(), Mainmenu.class);
startActivity(reload);
}else{
AlertDialog.Builder builder = new AlertDialog.Builder(Mainmenu.this);
builder.setMessage("Are u sure to want to Logout ?");
builder.setCancelable(false);
builder.setPositiveButton("yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent reload = new Intent(getApplicationContext(), Login.class);
startActivity(reload);
}
});
builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
}
return super.onOptionsItemSelected(item);
};
}
你也可以發佈你的適配器? –
請更改您的問題 –