I sorted listview
by category, by the following.
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
if(item.toString().equalsIgnoreCase("Reported Date"))
{
SortByRepDateAdapter sortAdapter= new SortByRepDateAdapter(getActivity(), defList);
listDefect.setAdapter(sortAdapter);
}
else if(item.toString().equalsIgnoreCase("Unit"))
{
sortByUnitAdapter sortByUnitAdapter= new sortByUnitAdapter(getActivity(), defList);
listDefect.setAdapter(sortByUnitAdapter);
}
else if(item.toString().equalsIgnoreCase("Block"))
{
SortByBlockAdapter sortByBlockAdapter= new SortByBlockAdapter(getActivity(), defList);
listDefect.setAdapter(sortByBlockAdapter);
}
else if(item.toString().equalsIgnoreCase("Last Followup Date"))
{
SortByLastFDateAdapter sortByLastFDateAdapter= new SortByLastFDateAdapter(getActivity(), defList);
listDefect.setAdapter(sortByLastFDateAdapter);
}
else if(item.toString().equalsIgnoreCase("Scope"))
{
SortByScopeAdapter sortByScopeAdapter= new SortByScopeAdapter(getActivity(), defList);
listDefect.setAdapter(sortByScopeAdapter);
}
else if(item.toString().equalsIgnoreCase("Subcontractor"))
{
SortBySubConAdapter sortBySubconAdapter= new SortBySubConAdapter(getActivity(), defList);
listDefect.setAdapter(sortBySubconAdapter);
}
Toast.makeText(getActivity(), "Sorted By "+
item.toString(),
Toast.LENGTH_LONG).show();
return true;
}
});
popupMenu.show();
}
I sorted listview
by calling different Adapters according to the category in menu.
The problem is after the listview
is sorted, listview.OnItemClickListener
not working.
I want to go new detail Activity when I click on each listView
row. Please help me.
Here is my code.
public class RectificationAct extends Fragment implements OnDataRetrieveComplete, OnItemClickListener{
protected static final String TAG = RectificationAct.class.getSimpleName();
private View view;
private Button btnSort;
private ListView listDefect;
private ListViewAdapter adapter;
private WebHelper webHelper;
private String projId;
ArrayList<DefectRecord> defList= new ArrayList<DefectRecord>();
private ArrayList<ListItem_Defect> listItems=new ArrayList<ListItem_Defect>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
webHelper = new WebHelper(this);
projId= FragHelper.getSF(StaticHelper.PROJID, getActivity());
Log.i(TAG,"projID=>"+projId);
webHelper.getDefectRecord(projId);
view= inflater.inflate(R.layout.frag_retification, container, false);
listDefect=(ListView) view.findViewById(R.id.listView_main);
listDefect.setOnItemClickListener(this);
btnSort=(Button)view.findViewById(R.id.btnSort);
btnSort.setOnClickListener(onSortListener);
return view;
}
final OnClickListener onSortListener= new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
showPopupMenu(v);
}
};
private void showPopupMenu(View v){
PopupMenu popupMenu = new PopupMenu(getActivity(), v);
popupMenu.getMenuInflater().inflate(R.menu.popup_sort, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
if(item.toString().equalsIgnoreCase("Reported Date"))
{
SortByRepDateAdapter sortAdapter= new SortByRepDateAdapter(getActivity(), defList);
listDefect.setAdapter(sortAdapter);
}
else if(item.toString().equalsIgnoreCase("Unit"))
{
sortByUnitAdapter sortByUnitAdapter= new sortByUnitAdapter(getActivity(), defList);
listDefect.setAdapter(sortByUnitAdapter);
}
else if(item.toString().equalsIgnoreCase("Block"))
{
SortByBlockAdapter sortByBlockAdapter= new SortByBlockAdapter(getActivity(), defList);
listDefect.setAdapter(sortByBlockAdapter);
}
else if(item.toString().equalsIgnoreCase("Last Followup Date"))
{
SortByLastFDateAdapter sortByLastFDateAdapter= new SortByLastFDateAdapter(getActivity(), defList);
listDefect.setAdapter(sortByLastFDateAdapter);
}
else if(item.toString().equalsIgnoreCase("Scope"))
{
SortByScopeAdapter sortByScopeAdapter= new SortByScopeAdapter(getActivity(), defList);
listDefect.setAdapter(sortByScopeAdapter);
}
else if(item.toString().equalsIgnoreCase("Subcontractor"))
{
SortBySubConAdapter sortBySubconAdapter= new SortBySubConAdapter(getActivity(), defList);
listDefect.setAdapter(sortBySubconAdapter);
}
Toast.makeText(getActivity(), "Sorted By "+
item.toString(),
Toast.LENGTH_LONG).show();
return true;
}
});
popupMenu.show();
}
@Override
public void onDataTaken(ArrayList<Block_Unit_Level>lvl_unt, ArrayList<DefectRecord> d_arr) {
listItems.clear();
defList=d_arr;
/*for (Block_Unit_Level uLvl_Obj : lvl_unt) {
listItems.add(new Block_Unit_Level(uLvl_Obj.get("block"), uLvl_Obj.get("level"), uLvl_Obj.get("unit")));*/
for (DefectRecord defect : d_arr)
{
/*if(uLvl_Obj.get("level").equalsIgnoreCase(defect.get("level")) && uLvl_Obj.get("unit").equalsIgnoreCase(defect.get("unit")))
{*/
//listItems.add(new Defect(defect.get("id"), defect.get("unit"), defect.get("level"), defect.get("scope_name"), defect.get("priority"), defect.get("description")));
listItems.add(new DefectRecord(defect.get("unit"), defect.get("level"), defect.get("block"),
defect.get("created_date"), defect.get("sub_con"), defect.get("scope"), defect.get("followup"),
defect.get("followup_date")));
//}
}
//}
adapter = new ListViewAdapter(getActivity(), listItems);
listDefect.setAdapter(adapter);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode==StaticHelper.requestCode_Rect)
{
CommunicationHelper.update_in_photo_upload(getActivity());
refreshView();
}
}
public void refreshView()
{
webHelper.getDefectRecord(projId);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
// TODO Auto-generated method stub
Defect item = (Defect)listItems.get(position);
String id=item.get("id");
Intent intent = new Intent (getActivity(), Rectification_DetailAct.class);
Bundle b=new Bundle();
b.putString("defect_id", id);
intent.putExtras(b);
startActivityForResult(intent, StaticHelper.requestCode_Rect);
}}
Try ListFrament instead of Fragment hope it helps