Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在listview中单击打开android活动需要很长时间_Android_Performance_Listview_Android Listview - Fatal编程技术网

在listview中单击打开android活动需要很长时间

在listview中单击打开android活动需要很长时间,android,performance,listview,android-listview,Android,Performance,Listview,Android Listview,我试图理解为什么单击activity1中的listview项目需要一段日志时间(大约1秒)才能打开第二个活动 我的代码似乎存在实现或性能问题 第一个活动(主)显示一个listview 第二个活动(Detail_annonce)显示listview项的详细信息 以下是我的第一个活动(主)的代码摘录,用于绑定单击listview项: list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

我试图理解为什么单击activity1中的listview项目需要一段日志时间(大约1秒)才能打开第二个活动

我的代码似乎存在实现或性能问题

  • 第一个活动(主)显示一个listview
  • 第二个活动(Detail_annonce)显示listview项的详细信息
以下是我的第一个活动(主)的代码摘录,用于绑定单击listview项:

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                            Annonce currentAnnonce = (Annonce) list.getAdapter().getItem(position);
                            String titre = currentAnnonce.getTitle();
                            String cat = currentAnnonce.getCategorie();
                            String desc = currentAnnonce.getDescription();
                            String etat = currentAnnonce.getEtat();
                            String img = currentAnnonce.getImage();
                            String prix = currentAnnonce.getPrix();
                            String villeObj = currentAnnonce.getVilleObjet();
                            String codePostal = currentAnnonce.getCode_postal();
                            String departement = currentAnnonce.getDepartement();
                            String avatarUser = currentAnnonce.getImageUser();
                            String pseudoUser = currentAnnonce.getPseudoUser();
                            String dateDebut = currentAnnonce.getDate_debut();
                            String idAnnonce = currentAnnonce.getId();
                            String emailUser = currentAnnonce.getEmailUser();
                            String partel = currentAnnonce.getPartel();
                            String parmail = currentAnnonce.getParmail();

                            Intent myIntent = new Intent(Main_All_Annonces.this, Detail_annonce.class);
                            myIntent.putExtra("titre", titre);
                            myIntent.putExtra("cat", cat);
                            myIntent.putExtra("desc", desc);
                            myIntent.putExtra("etat", etat);
                            myIntent.putExtra("img", img);
                            myIntent.putExtra("prix", prix);
                            myIntent.putExtra("villeObj", villeObj);
                            myIntent.putExtra("codePostal", codePostal);
                            myIntent.putExtra("departement", departement);
                            myIntent.putExtra("avatarUser", avatarUser);
                            myIntent.putExtra("pseudoUser", pseudoUser);
                            myIntent.putExtra("dateDebut", dateDebut);
                            myIntent.putExtra("idAnnonce", idAnnonce);
                            myIntent.putExtra("emailUser", emailUser);
                            myIntent.putExtra("partel", partel);
                            myIntent.putExtra("parmail", parmail);

                            myIntent.putExtra("parentAct", "AllAnnonces");

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                // get the common element for the transition in this activity
                                final View image_view = findViewById(R.id.allannonces_image);

                                //String transitionName = (String) view.getTag(R.id.allannonces_image);
                                ActivityOptionsCompat options =
                                        ActivityOptionsCompat.makeSceneTransitionAnimation(
                                                Main_All_Annonces.this,
                                                view,           // The view which starts the transition
                                                "transitionImg"  // The transitionName of the view we’re transitioning to
                                        );

                                // put more extras in the intent if you want, like the object clicked
                                myIntent.putExtra("EXTRA_IMAGE_TRANSITION_NAME", "transitionImg");
                                ActivityCompat.startActivity(Main_All_Annonces.this, myIntent, options.toBundle());
                            }
                            else {
                                // Code to run on older devices
                                startActivity(myIntent);
                                overridePendingTransition(R.anim.left_to_right, R.anim.right_to_left);
                            }

                        }
                    });
list.setOnItemClickListener(新的AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
Annonce currentAnnonce=(Annonce)list.getAdapter().getItem(位置);
字符串titre=currentAnnonce.getTitle();
字符串cat=currentAnnonce.getCategorie();
字符串desc=currentAnnonce.getDescription();
字符串etat=currentAnnonce.getEtat();
字符串img=currentAnnonce.getImage();
字符串prix=currentAnnonce.getPrix();
字符串villeObj=currentAnnonce.getVilleObjet();
字符串codePostal=currentAnnonce.getCode_postal();
字符串department=currentAnnonce.GetDepartment();
字符串avatarUser=currentAnnonce.getImageUser();
字符串pseudoUser=currentAnnonce.getPseudoUser();
String datedefesth=currentAnnonce.getDate_defesth();
字符串idAnnonce=currentAnnonce.getId();
字符串emailUser=currentAnnonce.getEmailUser();
字符串partel=currentAnnonce.getPartel();
字符串parmail=currentAnnonce.getParmail();
Intent myIntent=newintent(Main\u All\u Annonces.this,Detail\u annonone.class);
myIntent.putExtra(“滴度”,滴度);
myIntent.putExtra(“猫”,猫);
myIntent.putExtra(“描述”,描述);
myIntent.putExtra(“etat”,etat);
myIntent.putExtra(“img”,img);
myIntent.putExtra(“prix”,prix);
myIntent.putExtra(“villeObj”,villeObj);
myIntent.putExtra(“codePostal”,codePostal);
myIntent.putExtra(“部门”,部门);
myIntent.putExtra(“化身”,化身);
putExtra(“伪用户”,伪用户);
myIntent.putExtra(“日期首秀”,日期首秀);
myIntent.putExtra(“idAnnonce”,idAnnonce);
myIntent.putExtra(“emailUser”,emailUser);
我的意图。puttera(“partel”,partel);
myIntent.putExtra(“parmail”,parmail);
myIntent.putExtra(“父母法案”、“AllAnnonces”);
if(Build.VERSION.SDK\u INT>=Build.VERSION\u code.LOLLIPOP){
//获取此活动中转换的公共元素
最终视图图像\u视图=findViewById(R.id.allannonces\u图像);
//String transitionName=(String)view.getTag(R.id.allannonces\u image);
活动选项兼容选项=
ActivityOptions Compat.MakeScenetTransitionAnimation(
主要的,所有的,
视图,//开始转换的视图
“TransitionMg”//我们要转换到的视图的transitionName
);
//如果需要,可以在意图中添加更多附加内容,如单击的对象
myIntent.putExtra(“额外图像、过渡名称”、“过渡MG”);
ActivityCompat.startActivity(Main_All_Annonces.this、myIntent、options.toBundle());
}
否则{
//要在旧设备上运行的代码
星触觉(myIntent);
覆盖转换(R.anim.left\u到右,R.anim.right\u到左);
}
}
});
以下是“我的详细信息”活动的代码:

public class Detail_annonce extends Activity {

    HttpPost httppost;
    StringBuffer buffer;
    HttpClient httpclient;
    List<NameValuePair> nameValuePairs;
    ProgressDialog dialog = null;
    DisplayImageOptions options;
    LinearLayout btn_mail, btn_tel, btn_share;
    View bar1, bar2;
    String partel, parmail;
    TextView nbAnnonceActionBar ;


    @SuppressWarnings("unused")
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.detail_layout);

        Typeface robotolight = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Light.ttf");
        Typeface robotoBold = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Bold.ttf");
        Typeface robotoRegular = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Roboto/Roboto-Regular.ttf");

        bar1 = (View) findViewById(R.id.detail_view1);
        bar2 = (View) findViewById(R.id.detail_view2);

        options = new DisplayImageOptions.Builder()
                .displayer(new RoundedBitmapDisplayer(2000))
                .cacheOnDisc(true)
                .build();

        Intent previous = getIntent();
        Bundle extras = previous.getExtras();
        final String titre = extras.getString("titre");
        String cat = extras.getString("cat");
        String desc = extras.getString("desc");
        String img = extras.getString("img");
        final String prix = extras.getString("prix");
        final String villeObj = extras.getString("villeObj");
        final String codePostal = extras.getString("codePostal");
        String avatarUser = extras.getString("avatarUser");
        final String pseudoUser = extras.getString("pseudoUser");
        String dateDebut = extras.getString("dateDebut");
        final String idAnnonce = extras.getString("idAnnonce");
        final String emailUser = extras.getString("emailUser");
        partel = extras.getString("partel");
        parmail = extras.getString("parmail");
        String parentAct = extras.getString("parentAct");

        ImageView image_txt = (ImageView) findViewById(R.id.detail_annonce_image);
        TextView titre_txt = (TextView) findViewById(R.id.detail_annonce_titre);
        TextView prix_txt = (TextView) findViewById(R.id.detail_annonce_prix);
        TextView dateDebut_txt = (TextView) findViewById(R.id.detail_annonce_date_debut);
        TextView villeAndCodePostal = (TextView) findViewById(R.id.detail_annonce_ville_and_codePos);

        ImageLoader imageLoader = ImageLoader.getInstance();

        Double latitude = null, longitude = null;
        Geocoder geo = new Geocoder(getBaseContext(), Locale.getDefault());
        try {
            List<Address> addresses = geo.getFromLocationName(villeObj, 10);
            Address currentFound = addresses.get(0);
            if (currentFound.hasLatitude() && currentFound.hasLongitude()) {
                latitude = currentFound.getLatitude();
                longitude = currentFound.getLongitude();
            }
        } catch (IOException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        ViewCompat.setTransitionName(image_txt, getIntent().getStringExtra("EXTRA_IMAGE_TRANSITION_NAME"));
        imageLoader.displayImage(img, image_txt);

        titre_txt.setText(titre);
        titre_txt.setTypeface(robotoRegular);

        prix_txt.setText("€" + prix + ",00 EUR");
        prix_txt.setTypeface(robotolight);

        villeAndCodePostal.setText("Disponible à " +villeObj);
        villeAndCodePostal.setTypeface(robotolight);

        ////////////////
        /// DATE
        ////////////////
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
        Date pDate;
        try {
            pDate = df.parse(dateDebut);
            dateDebut = DateUtils.getDateDifference(pDate);
            dateDebut = dateDebut.replace("-", "");
        } catch (ParseException e) {
            Log.e("DATE PARSING", "Error parsing date..");
        }

        dateDebut_txt.setText("Posté il y a " + dateDebut + "dans la catégorie " +cat);
        dateDebut_txt.setTypeface(robotolight);

        if (latitude != null && longitude != null ) {
            // Get a handle to the Map Fragment
            GoogleMap map = ((MapFragment) getFragmentManager() .findFragmentById(R.id.map)).getMap();

            LatLng ville = new LatLng(latitude, longitude);

            map.setMyLocationEnabled(true);
            map.moveCamera(CameraUpdateFactory.newLatLngZoom(ville, 9));

            map.addMarker(new MarkerOptions()
                    .title(villeObj)
                    .visible(true)
                    .snippet("La vente se fait à cet adresse.")
                    .position(ville));
        }
public class Detail\u annonce扩展活动{
HttpPost-HttpPost;
字符串缓冲区;
HttpClient-HttpClient;
列出nameValuePairs;
ProgressDialog=null;
显示图像选项;
直线布局btn_邮件、btn_电话、btn_共享;
视图栏1、栏2;
弦花,帕尔马;
文本视图nbAnnonceActionBar;
@抑制警告(“未使用”)
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(右布局、详细布局);
Typeface robotolight=Typeface.createFromAsset(getApplicationContext().getAssets(),“fonts/Roboto/Roboto Light.ttf”);
Typeface robotoBold=Typeface.createFromAsset(getApplicationContext().getAssets(),“font/Roboto/Roboto Bold.ttf”);
Typeface robotoRegular=Typeface.createFromAsset(getApplicationContext().getAssets(),“font/Roboto/Roboto Regular.ttf”);
bar1=(视图)findViewById(R.id.detail_视图1);
bar2=(视图)findViewById(R.id.detail_视图2);
选项=新的DisplayImageOptions.B