没有在Android中获取ListView项目

时间:2016-10-21 06:27:35

标签: android json listview android-asynctask

当我可以使用新的Activity单击ListView项时,ListView没有打开。我不明白为什么不开放。

public class ActivityListOfSearchIDProfiles extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private ListView mListOfProfiles;
    private ArrayList<Registration> mArrayListOfRegistrations;
    private SearchByIDAdapter mSearchByIDAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.lay_activitylistview);

        mListOfProfiles = (ListView) findViewById(R.id.listOFSerachProfiles);

        Toolbar toolbar= (Toolbar) findViewById(R.id.toolbarCommon);
        setSupportActionBar(toolbar);
        toolbar.setTitleTextColor(Color.parseColor("#FFFFFF"));
        toolbar.setNavigationIcon(R.drawable.ic_action_navigation_arrow_back_inverted);
        getSupportActionBar().setIcon(R.mipmap.ic_action_account_circle);
        getSupportActionBar().setTitle("Profile");

        mArrayListOfRegistrations = new ArrayList<Registration>();

        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
                overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_right);
            }
        });

        final Intent intent = getIntent();
        String hjID = intent.getStringExtra("hjID");

        if (isConnected())
        {
            Toast.makeText(ActivityListOfSearchIDProfiles.this, "Profile:"+hjID, Toast.LENGTH_SHORT).show();
        }
        else {
            Toast.makeText(ActivityListOfSearchIDProfiles.this, "No Internet Connection Available", Toast.LENGTH_SHORT).show();
        }

        new SearchByIDGETThread(ActivityListOfSearchIDProfiles.this, new HandlerRegisterSearchProfile(), hjID).execute();
        System.out.println("With Thread");

        mListOfProfiles.setOnItemClickListener(this);

    }

    public boolean isConnected() {
        ConnectivityManager conManager = (ConnectivityManager) getSystemService(Activity.CONNECTIVITY_SERVICE);
        NetworkInfo networkInfo = conManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isConnected()) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {

        System.out.println("Open Listview Item");

        Registration mRegistration = mArrayListOfRegistrations.get(i);

        System.out.println("In listView Item");

        Intent intent = new Intent(ActivityListOfSearchIDProfiles.this, ActivityShowProfileDetails.class);

        intent.putExtra("fname", mRegistration.getFname());
        intent.putExtra("lname", mRegistration.getLname());
        intent.putExtra("hjID", mRegistration.getData());
        intent.putExtra("gender", mRegistration.getGender());
        intent.putExtra("dob", mRegistration.getDob());
        intent.putExtra("tob", mRegistration.getTob());
        intent.putExtra("age", mRegistration.getAge());

        intent.putExtra("height", mRegistration.getHeight());
        intent.putExtra("complexion", mRegistration.getComplexion());
        intent.putExtra("blood_group", mRegistration.getBlood_group());
        intent.putExtra("spect", mRegistration.getSpect());
        intent.putExtra("ph_dis", mRegistration.getPh_dis());
        intent.putExtra("nri", mRegistration.getNri());
        intent.putExtra("caste", mRegistration.getCast());
        intent.putExtra("rashi", mRegistration.getRashi());
        intent.putExtra("hob", mRegistration.getHob());
        intent.putExtra("city", mRegistration.getCity());
        intent.putExtra("state", mRegistration.getState());

        intent.putExtra("edu", mRegistration.getEdu());
        intent.putExtra("occupation", mRegistration.getOcc());
        intent.putExtra("place_occupation", mRegistration.getPlace_occ());
        intent.putExtra("income", mRegistration.getIncome());
        intent.putExtra("cat", mRegistration.getCat());

        intent.putExtra("father", mRegistration.getFather());
        intent.putExtra("mother", mRegistration.getMother());
        intent.putExtra("father_name", mRegistration.getFather_name());
        intent.putExtra("mother_name", mRegistration.getMother_name());
        intent.putExtra("mama_name", mRegistration.getMama_name());
        intent.putExtra("mama_place", mRegistration.getMama_place());
        intent.putExtra("rel_name", mRegistration.getRel_name());
        intent.putExtra("native_place", mRegistration.getNative_place());
        intent.putExtra("no_brothers", mRegistration.getNo_brothers());
        intent.putExtra("no_mar_bro", mRegistration.getNo_sisters());
        intent.putExtra("no_sisters", mRegistration.getNo_mar_bro());
        intent.putExtra("no_mar_sis", mRegistration.getNo_mar_sis());
        intent.putExtra("parent_occ", mRegistration.getParent_occ());
        intent.putExtra("family_property", mRegistration.getFamily_prop());
        intent.putExtra("expect", mRegistration.getExpectations());
        intent.putExtra("photo", mRegistration.getPhoto());
        intent.putExtra("photo2", mRegistration.getPhoto2());

        System.out.println("In ITem Search");

        System.out.println(intent.putExtra("family_property", mRegistration.getFamily_prop()));

        startActivity(intent);
    }
}

3 个答案:

答案 0 :(得分:0)

你应该设置诸如;

之类的Adapter
mListOfProfiles.setAdapter(
    new CustomProfileAdapter(this,mArrayListOfRegistrations));

如果没有设置适配器,则无法对列表进行充气。

答案 1 :(得分:0)

如果您在ListView上正确设置数据,请使用ListView的Onitemclick功能中的开关案例。如下代码: -

 @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {

        switch (adapterView.getId())
        {
            case R.id.listOFSerachProfiles:
                 Intent intent = new Intent(ActivityListOfSearchIDProfiles.this, ActivityShowProfileDetails.class);

    intent.putExtra("fname", mRegistration.getFname());
    intent.putExtra("lname", mRegistration.getLname());
    intent.putExtra("hjID", mRegistration.getData());
    intent.putExtra("gender", mRegistration.getGender());
    intent.putExtra("dob", mRegistration.getDob());
    intent.putExtra("tob", mRegistration.getTob());
    intent.putExtra("age", mRegistration.getAge());

    intent.putExtra("height", mRegistration.getHeight());
    intent.putExtra("complexion", mRegistration.getComplexion());
    intent.putExtra("blood_group", mRegistration.getBlood_group());
    intent.putExtra("spect", mRegistration.getSpect());
    intent.putExtra("ph_dis", mRegistration.getPh_dis());
    intent.putExtra("nri", mRegistration.getNri());
    intent.putExtra("caste", mRegistration.getCast());
    intent.putExtra("rashi", mRegistration.getRashi());
    intent.putExtra("hob", mRegistration.getHob());
    intent.putExtra("city", mRegistration.getCity());
    intent.putExtra("state", mRegistration.getState());

    intent.putExtra("edu", mRegistration.getEdu());
    intent.putExtra("occupation", mRegistration.getOcc());
    intent.putExtra("place_occupation", mRegistration.getPlace_occ());
    intent.putExtra("income", mRegistration.getIncome());
    intent.putExtra("cat", mRegistration.getCat());

    intent.putExtra("father", mRegistration.getFather());
    intent.putExtra("mother", mRegistration.getMother());
    intent.putExtra("father_name", mRegistration.getFather_name());
    intent.putExtra("mother_name", mRegistration.getMother_name());
    intent.putExtra("mama_name", mRegistration.getMama_name());
    intent.putExtra("mama_place", mRegistration.getMama_place());
    intent.putExtra("rel_name", mRegistration.getRel_name());
    intent.putExtra("native_place", mRegistration.getNative_place());
    intent.putExtra("no_brothers", mRegistration.getNo_brothers());
    intent.putExtra("no_mar_bro", mRegistration.getNo_sisters());
    intent.putExtra("no_sisters", mRegistration.getNo_mar_bro());
    intent.putExtra("no_mar_sis", mRegistration.getNo_mar_sis());
    intent.putExtra("parent_occ", mRegistration.getParent_occ());
    intent.putExtra("family_property", mRegistration.getFamily_prop());
    intent.putExtra("expect", mRegistration.getExpectations());
    intent.putExtra("photo", mRegistration.getPhoto());
    intent.putExtra("photo2", mRegistration.getPhoto2());

    System.out.println("In ITem Search");

    System.out.println(intent.putExtra("family_property", mRegistration.getFamily_prop()));

    startActivity(intent);
                break;
        }
    }

希望此代码可以帮助您: - )

答案 2 :(得分:0)

将ListActivity扩展到ActivityListOfSearchIDProfiles更好。然后创建ArrayAdapter或自定义listAdapter并将数据列表添加到适配器。然后将Adapter设置为listview。