不调用onListItemClick方法

时间:2014-10-08 13:21:32

标签: android listview android-listfragment

我正在处理一个代码段,其中单击列表视图项时未调用onListItemClick。我使用的是ListFragment,我已经实现了以下代码

 public class InboxFragment extends ListFragment {

 protected List<ParseObject> mMessages;
 ListView list;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_inbox, container, false);

    return rootView;
}

@Override
public void onResume() {
    super.onResume();
    getActivity().setProgressBarIndeterminate(true);

    ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(ParseConstants.CLASS_MESSAGES);
    query.whereEqualTo(ParseConstants.KEY_RECIPIENTS_IDS, ParseUser.getCurrentUser().getObjectId());
    query.addAscendingOrder(ParseConstants.KEY_CREATED_AT);
    query.findInBackground(new FindCallback<ParseObject>() {

        @Override
        public void done(List<ParseObject> messages, ParseException e) {
            if(e == null) {
                mMessages = messages;

                String[] usernames = new String[mMessages.size()];
                int i = 0;
                for(ParseObject message : mMessages){
                    usernames[i] = message.getString(ParseConstants.KEY_SENDER_NAME);
                    i++;
                }
                MessageAdapter adapter = new MessageAdapter(getListView().getContext(), mMessages);
                setListAdapter(adapter);
            }
        }
    });
}

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);

    ParseObject message = mMessages.get(position);
    String messageType = message.getString(ParseConstants.KEY_FILE_TYPE);
    ParseFile file = message.getParseFile(ParseConstants.KEY_FILE);
    Uri fileUri = Uri.parse(file.getUrl());

    if(message.equals(ParseConstants.TYPE_IMAGE)) {
        //view Image

        Intent intent = new Intent(getActivity() , ViewImageActivity.class);
        intent.setData(fileUri);
        startActivity(intent);
    } else {
        //view Video
    }
}

}

和inbox片段xml文件如下

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context="com.nayana.mymessengerapp.MainActivity$PlaceholderFragment"
android:clickable="false" >

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >
</ListView>

<TextView
    android:id="@android:id/empty"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/empty_inbox_lable" />

1 个答案:

答案 0 :(得分:0)

尝试这个,如果这给输出点击监听器工作。

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    System.out.println(l.getItemAtPosition(position))
}