我有一个列表视图,该列表视图从服务器获取数据并将其列出到列表视图中。 通过单击对话框警报显示给用户的项目 我的代码在api级别26上运行良好,但是当我在api级别24的设备上运行项目时,侦听器无法正常工作,什么也没发生。.
我的侦听器在一个片段中,代码如下:
public class bedehKariHa extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_bedehkariha, container, false);
set_bedehkariha_list(v);
return v;
}
public void set_bedehkariha_list(View v) {
new JSONDownloader("http://famila1.ir/khabgah/get_khabgah_cash.php?member_id="+MainActivity.LogedInMemberID, new JSONDownloader.OnLoadCallback() {
@Override
public void onDone(final String jDownloderData) {
final List<HashMap<String, Object>> data;
cashParser cashparse = new cashParser();
data = cashparse.bedehkariHaparse(jDownloderData);
String[] from = {"dong","hazine", "tozihat", "hazine_shareTo0", "hazine_shareTo1", "hazine_shareTo2", "hazine_shareTo3", "hazine_shareTo4", "hazine_shareTo5", "who_paid0", "who_paid1", "who_paid2", "who_paid3", "who_paid4", "who_paid5", "date"};
int[] to = {R.id.bedehkariha_dong,R.id.mablaq_hazine, R.id.babate_hazine, R.id.moshtarak_ba1, R.id.moshtarak_ba2, R.id.moshtarak_ba3, R.id.moshtarak_ba4, R.id.moshtarak_ba5, R.id.moshtarak_ba6, R.id.pardakhtaz1, R.id.pardakhtaz2, R.id.pardakhtaz3, R.id.pardakhtaz4, R.id.pardakhtaz5, R.id.pardakhtaz6, R.id.tarikh_hazine};
SimpleAdapter myadapter = new SimpleAdapter(
getView().getContext(), data, R.layout.bedehkariha_row, from, to
);
final ListView lv = (ListView) getView().findViewById(R.id.list_bedehkariha);
lv.setAdapter(myadapter);
lv.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(null, "you are in on item click method", Toast.LENGTH_SHORT).show();
final HashMap<String,Object> test = data.get(i);
AlertDialog.Builder alert = new AlertDialog.Builder(getView().getContext());
alert
.setCancelable(false)
.setMessage("آیا از تسویه این بدهی اطمینان دارید؟"+"\n"+"مبلغ کل: "+ test.get("hazine") +"\n"+"بابت:"+ test.get("tozihat") + "\n"+"تاریخ:" + test.get("date") )
.setTitle("هشدار")
.setPositiveButton("بله مطمئنم",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String URL = "http://famila1.ir/khabgah/set_data.php?cashID="+test.get("id")+"&memberID="+test.get("member_id")+"&whoPaidID="+MainActivity.LogedInMemberID;
new JSONDownloader(URL, new JSONDownloader.OnLoadCallback() {
@Override
public void onDone(final String s) {
AlertDialog.Builder alret = new AlertDialog.Builder(getView().getContext());
alret.setTitle("توجه!");
if (s.contains("done")){
alret.setMessage("درخواست تسویه حساب شما با موفقیت ثبت گردید و پس از تایید از مامان خرج درج می گردد");
}else{
alret.setMessage("درخواست ثبت تسویه حساب شما با خطا مواجه شد، لطفا بعدا مجددا تلاش فرمایید");
}
alret.create().show();
}
}).execute();
}
})
.setNegativeButton("لفو", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getView().getContext(), "در خواست شما لغو گردید", Toast.LENGTH_SHORT).show();
}
});
alert.create().show();
}
}
);
}
}).execute();
}
}
此问题在api级别24的此行中不存在:
lv.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {