我检查了以前有关此问题的所有问题,但没有一个对我有帮助。
我正在尝试在列表视图onItemClickListener
中打开新活动,但未打开新活动。在android监视器中,它显示
“ D / ViewRootImpl:ViewPostImeInputStage ACTION_DOWN”。
当我单击列表视图中的项目时,onItemClickListener
没有响应...可以打开吗?
该活动已成功运行,但是我无法收听列表点击事件。
该如何纠正?
这是我的课程:
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.banyan.simtaa_erp.R;
import com.example.banyan.simtaa_erp.activity.Activity_Add_Enquiry;
import com.example.banyan.simtaa_erp.activity.Activity_Enquiry_Description;
import com.example.banyan.simtaa_erp.adapter.Adapter_Enquiry_List;
import com.example.banyan.simtaa_erp.global.App_Config;
import com.example.banyan.simtaa_erp.global.Session_Manager;
import com.sdsmdg.tastytoast.TastyToast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import dmax.dialog.SpotsDialog;
import static com.willy.ratingbar.BaseRatingBar.TAG;
public class Fragment_Enquiry_List extends Fragment implements SwipeRefreshLayout.OnRefreshListener {
public Fragment_Enquiry_List() {
}
private FloatingActionButton fab_enquiry;
String str_user_name, str_user_id,str_select_task_id;
private ProgressDialog pDialog;
private SpotsDialog dialog_load_more;
public static RequestQueue queue;
Session_Manager session;
private SwipeRefreshLayout enquiry_list_swipe_refresh_layout;
private ListView enquiry_listView;
public static final String TAG_ID= "id";
public static final String TAG_CUSTOMER_ID = "cus_id";
public static final String TAG_IMAGE_ENQUIRY = "image";
public static final String TAG_DESCRIPTION = "description";
public static final String TAG_DATE_ENQUIRY = "date";
public static final String TAG_PROJECT_STATUS = "project_status";
public static final String TAG_CREATED_USERID = "created_userid";
public static final String TAG_CREATED_USERROLE = "created_userrole";
public static final String TAG_CREATED_DATETIME = "created_datetime";
public static final String TAG_CUSTOMER_DETAILS = "customer_details";
int int_starting_item_no = 0, int_last_item_no = 0, int_load_more_count = 100;
public Adapter_Enquiry_List Adapter;
static ArrayList<HashMap<String, String>> enquiry_list;
HashMap<String, String> params = new HashMap<String, String>();
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_enquiry_list, container, false);
session = new Session_Manager(getActivity());
session.checkLogin();
HashMap<String, String> user = session.getUserDetails();
str_user_id = user.get(Session_Manager.KEY_USER_ID);
str_user_name = user.get(Session_Manager.KEY_USER_NAME);
System.out.println("USER ID from Session ::::" + str_user_id);
System.out.println("USER NAME from Session ::::" + str_user_name);
enquiry_listView = (ListView) rootView.findViewById(R.id.list_enquiry_list);
fab_enquiry = (FloatingActionButton) rootView.findViewById(R.id.fab_enquiry);
enquiry_list_swipe_refresh_layout = (SwipeRefreshLayout) rootView.findViewById(R.id.enquiry_list_swipe_refresh_layout);
enquiry_list_swipe_refresh_layout.setOnRefreshListener(this);
enquiry_list = new ArrayList<HashMap<String, String>>()
enquiry_list_swipe_refresh_layout.post(new Runnable() {
@Override
public void run() {
try {
enquiry_list_swipe_refresh_layout.setRefreshing(true);
queue = Volley.newRequestQueue(getActivity().getApplicationContext());
Activity_Get_Enquiry_List(int_starting_item_no, int_load_more_count);
} catch (Exception e) {
}
}
});
enquiry_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
System.out.println("Event Trigered by Item" );
String str_enquiry_id = enquiry_list.get(position).get(TAG_ID);
String str_customer_id = enquiry_list.get(position).get(TAG_CUSTOMER_ID);
String str_image_enquiry = enquiry_list.get(position).get(TAG_IMAGE_ENQUIRY);
String str_description_enquiry = enquiry_list.get(position).get(TAG_DESCRIPTION);
String str_date_enquiry = enquiry_list.get(position).get(TAG_DATE_ENQUIRY);
String str_project_status = enquiry_list.get(position).get(TAG_PROJECT_STATUS);
String str_created_userid = enquiry_list.get(position).get(TAG_CREATED_USERID);
String str_created_userrole = enquiry_list.get(position).get(TAG_CREATED_USERROLE);
String str_created_datetime = enquiry_list.get(position).get(TAG_CREATED_DATETIME);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("enquiry_id", str_enquiry_id);
editor.putString("customer_id", str_customer_id);
editor.putString("image_enquiry", str_image_enquiry);
editor.putString("description_enquiry", str_description_enquiry);
editor.putString("date_enquiry", str_date_enquiry);
editor.putString("project_status", str_project_status);
editor.putString("created_userid", str_created_userid);
editor.putString("created_role", str_created_userrole);
editor.putString("created_datetime", str_created_datetime);
editor.commit();
Intent i = new Intent(getContext(),Activity_Enquiry_Description.class);
startActivity(i);
}
});
enquiry_listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) {
// TODO Auto-generated method stub
str_select_task_id = enquiry_list.get(pos).get(TAG_ID);
Delete_Task_alert();
return true;
}
});
return rootView;
}
private void Activity_Get_Enquiry_List(final int int_starting_item_no, final int int_load_more_count) {
StringRequest request = new StringRequest(Request.Method.POST, App_Config.url_list_enquiry, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG_CUSTOMER_DETAILS, response.toString());
Log.d("TAG_ENQUIRY_LIST", response.toString());
try {
JSONObject obj = new JSONObject(response);
System.out.println("REG 00" + obj);
int success = obj.getInt("success");
System.out.println("REG" + success);
if (success == 1) {
JSONArray enquiry = obj.getJSONArray("Enquiry");
for (int i = 0; enquiry.length() > i; i++) {
JSONObject obj_one = enquiry.getJSONObject(i);
String str_enquiry_id = obj_one.getString(TAG_ID);
String str_customer_id = obj_one.getString(TAG_CUSTOMER_ID);
String str_image_enquiry = obj_one.getString(TAG_IMAGE_ENQUIRY);
String str_description_enquiry = obj_one.getString(TAG_DESCRIPTION);
String str_date_enquiry = obj_one.getString(TAG_DATE_ENQUIRY);
String str_project_status = obj_one.getString(TAG_PROJECT_STATUS);
String str_created_userid = obj_one.getString(TAG_CREATED_USERID);
String str_created_userrole = obj_one.getString(TAG_CREATED_USERROLE);
String str_created_datetime = obj_one.getString(TAG_CREATED_DATETIME);
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
// adding each child node to HashMap key => value
map.put(TAG_ID, str_enquiry_id);
map.put(TAG_CUSTOMER_ID, str_customer_id);
map.put(TAG_IMAGE_ENQUIRY, str_image_enquiry);
map.put(TAG_DESCRIPTION, str_description_enquiry);
map.put(TAG_DATE_ENQUIRY, str_date_enquiry);
map.put(TAG_PROJECT_STATUS, str_project_status);
map.put(TAG_CREATED_USERID, str_created_userid);
map.put(TAG_CREATED_USERROLE, str_created_userrole);
map.put(TAG_CREATED_DATETIME, str_created_datetime);
enquiry_list.add(map);
System.out.println("HASHMAP ARRAY" + enquiry_list);
}
Adapter = new Adapter_Enquiry_List(getActivity(), enquiry_list);
enquiry_listView.setAdapter(Adapter);
enquiry_list_swipe_refresh_layout.setRefreshing(false);
} else {
TastyToast.makeText(getContext(), "OOPS FAILED TO LOAD", TastyToast.LENGTH_LONG, TastyToast.WARNING);
}
LoadMoreButtonVisible();
enquiry_list_swipe_refresh_layout.setRefreshing(false);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
enquiry_list_swipe_refresh_layout.setRefreshing(false);
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("user_id", str_user_id);
params.put("start",""+ int_starting_item_no);
params.put("limit",""+ int_load_more_count);
System.out.println("user_id " + str_user_id);
System.out.println("start " + int_starting_item_no);
System.out.println("limit " + int_load_more_count);
return params;
}
};
queue.add(request);
}
}
答案 0 :(得分:0)
您实现了列表项Click监听器的错误方法,只需替换
enquiry_listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
}
}
收件人:
enquiry_listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {}}
答案 1 :(得分:0)
如果list / Recyclerview的子视图中存在可单击的UI元素(如Button,Imagebutton),则它们可以控制click事件。因此,Recyclerview将没有机会单击事件。
请为所有子级可点击视图设置android:focusable="false"
。然后,您的itemclick将起作用。
您还可以在父视图中使用以下属性,以防止子视图获得焦点。
android:descendantFocusability="blocksDescendants"