当我点击某个项目时,为什么我的列表视图总会将一页返回给我?

时间:2016-07-07 15:18:16

标签: android listview

我的listview遇到问题。每当我按下列表中的项目时,它总会将我发回我的登录页面。它应该转到详细信息页面。

package com.example.kun.carcarkila;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.amigold.fundapter.BindDictionary;
import com.amigold.fundapter.FunDapter;
import com.amigold.fundapter.extractors.StringExtractor;
import com.amigold.fundapter.interfaces.DynamicImageLoader;
import com.kosalgeek.android.json.JsonConverter;
import com.kosalgeek.genasync12.AsyncResponse;
import com.kosalgeek.genasync12.PostResponseAsyncTask;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.io.Serializable;
import java.util.ArrayList;

public class HomeActivity extends AppCompatActivity implements AsyncResponse, AdapterView.OnItemClickListener {
final String LOG = "HomeActivity";

private ArrayList<Product> productList;
private ListView lvProduct;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);



    ImageLoader.getInstance().init(UILConfig.config(HomeActivity.this)); // Do it on Application start

    PostResponseAsyncTask taskRead = new PostResponseAsyncTask(HomeActivity.this, this);
    taskRead.execute("http://10.0.2.2/carkila/product.php");


}

@Override
public void processFinish(String s) {

            productList = new JsonConverter<Product>().toArrayList(s, Product.class);

    BindDictionary<Product> dict = new BindDictionary<Product>();

    dict.addDynamicImageField(R.id.ivImg, new StringExtractor<Product>() {
        @Override
        public String getStringValue(Product item, int position) {
            return item.img;
        }
    }, new DynamicImageLoader() {
        @Override
        public void loadImage(String url, ImageView imageView) {

            ImageLoader.getInstance().displayImage(url, imageView); // Default options will be used
        }
    });
    dict.addStringField(R.id.tvCarModel, new StringExtractor<Product>() {
        @Override
        public String getStringValue(Product item, int position) {
            return "Car Model: " + item.Car_Model;
        }
    });
    dict.addStringField(R.id.tvCarType, new StringExtractor<Product>() {
        @Override
        public String getStringValue(Product item, int position) {
            return "Car Type: " +  item.Car_Type;
        }
    });
    dict.addStringField(R.id.tvCapacity, new StringExtractor<Product>() {
        @Override
        public String getStringValue(Product item, int position) {
            return "Capacity: " + item.Capacity;
        }
    });

    FunDapter<Product> adapter = new FunDapter<>(
            HomeActivity.this, productList, R.layout.layout_list, dict);
    lvProduct = (ListView)findViewById(R.id.lvProduct);
    lvProduct.setAdapter(adapter);
    lvProduct.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Product selectedProduct = productList.get(position);
    Intent in = new Intent(HomeActivity.this, DetailActivity.class);
    in.putExtra("product", (Serializable) selectedProduct);
    startActivity(in);
}
}

我在youtube频道上学习了这段代码,我知道我很好地遵循了说明,而且我总是在检查意图,但仍然存在问题。谢谢你们提前。 :)

这是我的DetailActivity.class。这有问题吗?

package com.example.kun.carcarkila;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

public class DetailActivity extends AppCompatActivity {
TextView tvCarModel, tvCarType, tvCapacity;
ImageView ivImage;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ImageLoader.getInstance().init(UILConfig.config(DetailActivity.this));

    Product product = (Product) getIntent().getSerializableExtra("product");

    tvCarModel = (TextView)findViewById(R.id.tvCarModel);
    tvCarType = (TextView)findViewById(R.id.tvCarType);
    tvCapacity = (TextView)findViewById(R.id.tvCapacity);
    ivImage = (ImageView)findViewById(R.id.ivImage);

    if(product != null){
        tvCarModel.setText(product.Car_Model);
        tvCarType.setText(product.Car_Type);
        tvCapacity.setText(product.Capacity);
        ImageLoader.getInstance().displayImage(product.img, ivImage);
    }
}

}

Debug

in = {Intent@830622078952} "Intent { cmp=com.example.kun.carcarkila/.DetailActivity }"
mAction = null
mCategories = null
mClipData = null
mComponent = {ComponentName@830622081720} "ComponentInfo{com.example.kun.carcarkila/com.example.kun.carcarkila.DetailActivity}"
mData = null
mExtras = null
mType = null
mPackage = null
mSelector = null
mSourceBounds = null
mFlags = 0

0 个答案:

没有答案