确定两个背压

时间:2012-08-08 01:15:05

标签: android checkbox onclick android-listview

我有一些文本字段和一个按钮的视图。单击按钮后,我会看到一个列表视图。在那里我做了一些选择(存储在地图中),按下后退按钮后,我转到初始视图。当从视图中按下后退按钮时,它应将它们(映射值)和文本字段值存储到DB中。

然而,按下后退按钮在视图中定义。当我从列表视图中按下后退按钮时,视图中定义的按钮会被调用,但是当我从视图中按下它时,它不会被调用。如何过来呢?

btw我无法在列表视图中定义后退按钮调用..

有关如何解决此问题的任何想法?

编辑:

这是代码,

class PInfo {
    String appname = "";
    String pname = "";
    Drawable icon;
}

public class InstalledApps extends Activity{

private static LayoutInflater inflater=null;
private ListView listview;
private Activity activity;

List<PInfo> installedApps = new ArrayList<PInfo>();

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.applist);

    activity = this;
    listview = (ListView)findViewById(R.id.listView1);

    PackageManager pm = getPackageManager();
    List<ApplicationInfo> packages = pm.getInstalledApplications(PackageManager.GET_META_DATA);

    for(ApplicationInfo app : packages) {

        PInfo newInfo = new PInfo();

        newInfo.appname = (String) app.loadLabel(pm);
        newInfo.pname = app.packageName;
        //newInfo.icon = app.icon;
        //Drawable dd = activity.getResources().getDrawable(app.icon);
        newInfo.icon = app.loadIcon(getPackageManager());
        //System.out.println(android.os.Process.getUidForName(newInfo.pname));

        if((app.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) == 1) {        

            installedApps.add(newInfo);
        } else if ((app.flags & ApplicationInfo.FLAG_SYSTEM) == 1) {

            installedApps.add(newInfo);

        } else {

            installedApps.add(newInfo);

        }
    }


    InstalledAppsAdapter iap = new InstalledAppsAdapter(this, installedApps);
    listview.setAdapter(iap);



}

@Override
public void onBackPressed() {
    // TODO Auto-generated method stub
    super.onBackPressed();
    System.out.println("Back Pressed");

    //getSeletedApps() 


}



}

 class InstalledAppsAdapter extends BaseAdapter{


private Activity activity;
private static LayoutInflater inflater=null;
List<PInfo> installedApps = new ArrayList<PInfo>();
ListView listview; 
Map<String, String> appselect = new HashMap<String, String>(10); 

public InstalledAppsAdapter(Activity a, List<PInfo> b) {

    // TODO Auto-generated constructor stub
    installedApps = b;
    activity = a;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    listview = (ListView)activity.findViewById(R.id.listView1);


}

public void onBackPressed() {
    // TODO Auto-generated method stub
    //super.onBackPressed();
    System.out.println("Back Pressed1111111111");


}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return installedApps.size();
}

@Override
public Object getItem(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

@Override
public long getItemId(int arg0) {
    // TODO Auto-generated method stub
    return arg0;
}

@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
    // TODO Auto-generated method stub


    View  customView = inflater.inflate(R.layout.listrow, arg2,false);

    ImageView iv = (ImageView)customView.findViewById(R.id.imageView1);
    TextView tv= (TextView) customView.findViewById(R.id.textView2);
    CheckBox cb= (CheckBox)customView.findViewById(R.id.checkBox1);



   final PInfo pinfo = installedApps.get(arg0);
        tv.setText(""+pinfo.appname);//If u comment this line it works
        Drawable dd;
        /*if(pinfo.icon != 0){
            System.out.println(pinfo.icon);
            dd =  activity.getResources().getDrawable(pinfo.icon);
        }else{
            dd =  activity.getResources().getDrawable(R.drawable.ic_launcher);
        }*/
        iv.setImageDrawable(pinfo.icon);

        cb.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                // TODO Auto-generated method stub
                if(isChecked){

                    appselect.put(pinfo.pname, pinfo.appname);
                //System.out.println("AAAAAAAAAAAAA "+pinfo.appname);

                }else if(!isChecked){

                    appselect.remove(pinfo.pname);
                    //System.out.println("BBBBBBBBBBBBBBBB");
                }
            }
        });


    return customView;


}

public Map<String, String> getSeletedApps(){
    return appselect;
}

}

我只能在InstalledApps类中定义backpress。 (可以在InstalledAppsAdapter类中定义吗?)但是当我在listview中时它会被调用。从listview返回后我有一些文本字段,当我从这里按回按钮时,我需要将值保存到DB(listview返回值+文本字段)。我无法检测到第二次背压......

0 个答案:

没有答案