Android : onListItemClick method is not called

on Wednesday, October 8, 2014


Hello i am working on a code snippet where onListItemClick is not being called when clicked on item of list view


i am using ListFragment and i have implemented following code



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
}
}


}


and inbox fragment xml file is as follows



<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" />

0 comments:

Post a Comment