-3

I am trying to search for some data in Mysql database, then display it Listview

When more than 1 result is found, clicking on any one of them will take you to its respective details page.

But.. I am looking to go to details page directly if there is only one result in list view. Put simply, how would I call onItemClick on the list view automatically when there is only one item in the list.

My Listview's onClickItemListener looks like this:

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

    // when a student is selected then the following methods are called

    DetailsFragment.setLUNCH_TYPE(searchResult.get(position).lunchtype);
    Log.d("Lunch type selected", ""+DetailsFragment.getLUNCH_TYPE());
    ((HomeActivity) getActivity()).startStudentSale(searchResult
            .get(position).name.toString(),searchResult
            .get(position).isStudent,searchResult.get(position).id);

    // it was comming null here when running this this need to find out why
    // ((HomeActivity)getActivity()).setmSaleType(SALE_TYPE.SEARCHED_STUDENT);
}
4

1 回答 1

0

当你知道结果集的计数时,说cnt,如果它是1,即

  if(cnt==1){
   Intent intent=new Intent(getApplicationContext(),DetailActivity.class);
   startActivity(intent);
  }
于 2013-05-28T10:52:20.573 回答