Java 单击项目更改后要刷新列表视图吗

Java 单击项目更改后要刷新列表视图吗,java,android,Java,Android,我正在使用ListView从数据库中获取数据。 当我调用update和delete时,我通过调用Intent刷新活动。 它显示更新后的列表,但当我单击它时,它不会显示文本视图中的更改,我正在显示列表详细信息。 我正在使用自定义适配器。下面是我的代码 public class Mainmenu extends Activity{ ListView list; DBHandler db= new DBHandler(this); int ID; String strn

我正在使用ListView从数据库中获取数据。 当我调用update和delete时,我通过调用
Intent
刷新活动。 它显示更新后的列表,但当我单击它时,它不会显示文本视图中的更改,我正在显示列表详细信息。 我正在使用自定义适配器。下面是我的代码

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);
    };


}
public类主菜单扩展活动{
列表视图列表;
DBHandler db=新的DBHandler(此);
int-ID;
字符串strname、strlastname、strdob、strcell、strcnic、straddress;
字符串pppath、cfpath、cbpath、fppath;
TextView tvname、tvlastname、tvdob、tvcnic、tvcell、tvaddress;
ImageView pp、cf、cb;
public static ArrayList customers=new ArrayList();
搜索结果sr1;
ArrayList searchResults=新建ArrayList();
MyCustomBaseAdapter适配器;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenulist);
列表=(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();
}否则{
List gtEdu=db.getAllcustomers2();
客户。清除();
针对客户(编辑:gtEdu){
sr1=新的搜索结果();
ID=ed.getCID();
sr1.setId(ID);
添加(ed.getCustomer_Name());
strname=ed.getCustomer_Name().toString();
sr1.集合名(strname);
customers.add(ed.getCustomer_DOB());
strdob=ed.getCustomer_DOB().toString();
sr1.setDOB(strdob);
customers.add(ed.getCustomer_CNIC());
strcnic=ed.getCustomer\u CNIC().toString();
sr1.setCNIC(strcnic);
添加(ed.getCustomer_Cell());
strcell=ed.getCustomer_Cell().toString();
sr1.设置电话(strcell);
客户。添加(StradAddress);
StradAddress=ed.getCustomer_Address().toString();
sr1.设置地址(地址);
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.设置图像编号(1);
searchResults.add(sr1);
}
}
适配器=新的MyCustomBaseAdapter(c,搜索结果);
列表.设置适配器(适配器);
list.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父视图、视图、整型位置、,
长id){
内部高度=146;
整数宽度=146;
//parent.getItemAtPosition(位置);
//
Log.d(“PP”和“+pppath”);
Log.d(“cP”和“+cbpath”);
Log.d(“fP”和“+cfpath”);
//位图ppbitmap=BitmapFactory.decodeFile(pppath);
//位图cbbitmap=BitmapFactory.decodeFile(cbpath);
//位图cfbitmap=BitmapFactory.decodeFile(cfpath);
//ppbitmap=Bitmap.createScaledBitmap(ppbitmap,宽度,高度,真);
//cbbitmap=Bitmap.createScaledBitmap(cbbitmap,宽度,高度,真);
//cfbitmap=Bitmap.createScaledBitmap(cfbitmap,宽度,高度,true);
//              
//pp.setImageBitmap(ppbitmap);
//cb.setImageBitmap(cbbitmap);
//cf.setImageBitmap(CfitMap);
字符串[]结果=strname.split(“”);
strname=结果[0];
strlastname=结果[1];
tvname.setText(strname);
tvlastname.setText(strlastname);
tvcell.setText(strcell);
tvaddress.setText(straddress);
tvcnic.setText(strcnic);
tvdob.setText(strdob);
adaptor.notifyDataSetChanged();
}
}); 
list.setOnItemLongClickListener(新的OnItemLongClickListener(){
长单击(AdapterView arg0、视图arg1、,
内部位置,长id){
////TODO自动生成的方法存根
//              
//
db.getWritableDatabase();
//db.删除(ID);
//db.更新(17);
////TODO自动生成的方法存根
//
//Intent gonext=newintent(“com.example.ibex.main菜单”);
//星触觉(gonext);
//
AlertDialog.Builder=新建AlertDialog.Builder(主菜单.this);
setMessage(“选择任何一个!”);
builder.setCancelable(false);
setPositiveButton(“编辑”,新建DialogInterface.OnClickListener()){
@凌驾
public void onClick(DialogInterface dialog,int which){
数据库更新(ID);
意向重新加载=新意向(getApplicationContext(),Mainmenu.class);
星触觉(重新加载);